这道题是模拟加法的,没什么难度。
#include<stdio.h>
#include<string.h>
char st1[1005],st2[1005];
int st3[2005];
void Add()
{
int i1=strlen(st1)-1,i2=strlen(st2)-1;
int carry=0,tmp,i,j=0;
for(;i1>=0&&i2>=0;--i1,--i2,++j){
tmp=st1[i1]-'0'+st2[i2]-'0'+carry;
st3[j]=tmp%10;
carry=tmp/10;
}
while(i1>=0){
tmp=st1[i1--]-'0'+carry;
st3[j++]=tmp%10;
carry=tmp/10;
}
while(i2>=0){
tmp=st2[i2--]-'0'+carry;
st3[j++]=tmp%10;
carry=tmp/10;
}
if(carry) st3[j++]=carry;
printf("%s + %s = ",st1,st2);
for(i=j-1;i>=0;i--)
printf("%d",st3[i]);
printf("\n");
}
int main()
{
int t,cas=1;
scanf("%d",&t);
while(t--){
scanf("%s %s",st1,st2);
printf("Case %d:\n",cas++);
Add();
if(t) printf("\n");
}
}