传送门:点击打开链接
题意:大数加法的模拟题
AC代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{
//freopen("e:\\input.txt","r",stdin);
//freopen("e:\\output.txt","w",stdout);
char s1[1010],s2[1010],s3[1010],*q;
int i,j,k,t,Ls1,Ls2,Ls3,C1,C2,Q,len;
cin>>t;
for(k=1;k<=t;k++)
{
cin>>s1>>s2;
cout<<"Case "<<k<<":"<<endl;
cout<<s1<<" + "<<s2<<" = ";
Ls1=strlen(s1);
Ls2=strlen(s2);
i=Ls1-1;
j=Ls2-1;
Q=len=0;
while(i>=0 || j>=0)
{
C1=C2=0;
if(i>=0)
{
C1=s1[i]-'0';
i--;
}
if(j>=0)
{
C2=s2[j]-'0';
j--;
}
s3[len++]=(C1+C2+Q)%10+'0';
Q=(C1+C2+Q)/10;
}
if(Q) s3[len++]=Q+'0';
s3[len]=0;
q=s3;
q=strrev(q);
cout<<s3<<endl;
if(k!=t)
cout<<endl;
}
return 0;
}