首页 > 代码库 > 对拍练习:A+B
对拍练习:A+B
源程序:
1 /* 2 Problem: 3 OJ: 4 User: S.B.S. 5 Time: 6 Memory: 7 Length: 8 */ 9 #include<iostream>10 #include<cstdio>11 #include<cstring>12 #include<cmath>13 #include<algorithm>14 #include<queue>15 #include<cstdlib>16 #include<iomanip>17 #include<cassert>18 #include<climits>19 #include<functional>20 #include<bitset>21 #include<vector>22 #include<list>23 #define F(i,j,k) for(int i=j;i<=k;++i)24 #define M(a,b) memset(a,b,sizeof(a))25 #define FF(i,j,k) for(int i=j;i>=k;i--)26 #define maxn 1000127 #define inf 0x3f3f3f3f28 #define maxm 400129 #define mod 99824435330 #define LOCAL31 using namespace std;32 int read(){33 int x=0,f=1;char ch=getchar();34 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}35 while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}36 return x*f;37 }38 long long n,m;39 int main()40 {41 std::ios::sync_with_stdio(false);//cout<<setiosflags(ios::fixed)<<setprecision(1)<<y;42 #ifdef LOCAL43 freopen("in.txt","r",stdin);44 freopen("out2.out","w",stdout);45 #endif46 cin>>n>>m;47 cout<<n+m<<endl;48 return 0;49 }
对拍码:
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 #include<iostream> 5 #include<string> 6 #define rep(q,p) for(int q=1;q<=p;q++) 7 #define prt for (int i=l;i>0;i--) cout<<c[i] 8 using namespace std; 9 const int maxn=1e4+5;10 string sa,sb;11 int la,lb,a[maxn],b[maxn],c[maxn],l;12 bool ma,mb,m;13 inline void addbig(string ta,string tb)14 {15 la=ta.length(); lb=tb.length();16 for (int i=1;i<=la;i++)17 a[la-i+1]=sa[i-1]-‘0‘;18 for (int i=1;i<=lb;i++) 19 b[lb-i+1]=sb[i-1]-‘0‘;20 l=max(la,lb);21 rep(i,l)22 {23 c[i]+=a[i]+b[i];24 c[i+1]=c[i]/10;25 c[i]%=10;26 }27 if (c[l+1]) l++;28 }29 inline bool subbig(string ta,string tb)30 {31 la=ta.length(); lb=tb.length();32 bool mark=false;33 if (la<lb || (la==lb && tb>ta))34 {35 string tmp;36 tmp=ta; ta=tb; tb=tmp;37 swap(la,lb);38 mark=true;39 }40 for (int i=1;i<=la;i++)41 a[la-i+1]=ta[i-1]-‘0‘;42 for (int i=1;i<=lb;i++) 43 b[lb-i+1]=tb[i-1]-‘0‘;44 l=max(la,lb);45 rep(i,la)46 {47 c[i]+=a[i]-b[i];48 if (c[i]<0) c[i]+=10,c[i+1]--;49 c[i+1]+=c[i]/10;50 c[i]%=10;51 }52 while (l>1 && !c[l]) l--;53 return mark;54 }55 inline void mulbig(string ta,string tb)56 {57 la=ta.length(); lb=tb.length();58 for (int i=1;i<=la;i++)59 a[la-i+1]=ta[i-1]-‘0‘;60 for (int i=1;i<=lb;i++)61 b[lb-i+1]=tb[i-1]-‘0‘;62 rep(i,la) rep(j,lb)63 {64 c[i+j-1]+=a[i]*b[j];65 c[i+j]+=c[i+j-1]/10;66 c[i+j-1]%=10;67 }68 l=la+lb;69 while (!c[l] && l>1) l--;70 }71 int main()72 {73 freopen("in.txt","r",stdin);74 freopen("out1.out","w",stdout);75 cin>>sa>>sb;76 la=sa.length(); lb=sb.length();77 if (sa[0]==‘-‘)78 ma=1,sa=sa.substr(1,la);79 if (sb[0]==‘-‘)80 mb=1,sb=sb.substr(1,lb);81 if (!ma xor mb)82 {83 addbig(sa,sb);84 if (ma) cout<<‘-‘;85 prt;86 }87 else88 if (ma)89 {90 if (subbig(sb,sa)) cout<<‘-‘;91 prt;92 }93 else94 {95 if (subbig(sa,sb)) cout<<‘-‘;96 prt;97 }98 return 0;99 }
datamaker:
1 /* 2 Problem: 3 OJ: 4 User: S.B.S. 5 Time: 6 Memory: 7 Length: 8 */ 9 #include<iostream>10 #include<cstdio>11 #include<cstring>12 #include<cmath>13 #include<algorithm>14 #include<queue>15 #include<cstdlib>16 #include<iomanip>17 #include<cassert>18 #include<climits>19 #include<functional>20 #include<bitset>21 #include<vector>22 #include<list>23 24 #include<ctime>25 #define F(i,j,k) for(int i=j;i<=k;++i)26 #define M(a,b) memset(a,b,sizeof(a))27 #define FF(i,j,k) for(int i=j;i>=k;i--)28 #define maxn 1000129 #define inf 0x3f3f3f3f30 #define maxm 400131 #define mod 99824435332 #define LOCAL33 using namespace std;34 int read(){35 int x=0,f=1;char ch=getchar();36 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}37 while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}38 return x*f;39 }40 int n,m;41 int main()42 {43 std::ios::sync_with_stdio(false);//cout<<setiosflags(ios::fixed)<<setprecision(1)<<y;44 // freopen("data.in","r",stdin);45 freopen("in.txt","w",stdout);46 srand(time(NULL));47 cout<<rand()%(1<<20)<<endl;48 cout<<rand()%(1<<20)<<endl;49 return 0;50 }
对拍:
1 /* 2 Problem: 3 OJ: 4 User: S.B.S. 5 Time: 6 Memory: 7 Length: 8 */ 9 #include<iostream>10 #include<cstdio>11 #include<cstring>12 #include<cmath>13 #include<algorithm>14 #include<queue>15 #include<cstdlib>16 #include<iomanip>17 #include<cassert>18 #include<climits>19 #include<functional>20 #include<bitset>21 #include<vector>22 #include<list>23 #define F(i,j,k) for(int i=j;i<=k;++i)24 #define M(a,b) memset(a,b,sizeof(a))25 #define FF(i,j,k) for(int i=j;i>=k;i--)26 #define maxn 1000127 #define inf 0x3f3f3f3f28 #define maxm 400129 #define mod 99824435330 //#define LOCAL31 using namespace std;32 int read(){33 int x=0,f=1;char ch=getchar();34 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}35 while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}36 return x*f;37 }38 int n,m;39 int main()40 {41 std::ios::sync_with_stdio(false);//cout<<setiosflags(ios::fixed)<<setprecision(1)<<y;42 #ifdef LOCAL43 freopen("data.in","r",stdin);44 freopen("data.out","w",stdout);45 #endif46 int t=0;47 while(1){48 cout<<++t<<":"<<endl;49 system("data.exe");50 system("111.exe");51 system("222.exe");52 if(system("fc out1.out out2.out")) while(1);53 }54 return 0;55 }
对拍练习:A+B
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。