改成这样:
#include
#include
#define MAXN 1000
int max(int a,int b)
{
return a>b?a:b;
}
int main()
{
int i,j,k1,k2,t,n,f;
scanf("%d",&t);
for(i=0;i{
char s1[MAXN+1],s2[MAXN+1],r[MAXN+2] = {'\0'}; //数组在每次for循环开始时初始化,尤其r数组要初始化为‘\0’避免上一组数据影响结果
scanf("%s%s",s1,s2);
f=0;
n=max(strlen(s1),strlen(s2));
k1=strlen(s1)-1;
k2=strlen(s2)-1;
printf("Case %d:\n",i+1);
printf("%s + %s = ",s1,s2);
for(j=0;j{
r[j]=(s1[k1]+s2[k2]-2*'0'+f)%10;
f=(s1[k1]+s2[k2]-2*'0'+f)/10;
if(k1==0) s1[k1]='0';
if(k2==0) s2[k2]='0';
if(k1>0) k1--;
if(k2>0) k2--;
}
for(;r[j]<=0||r[j]>9;j--);
for(;j>=0;j--)
printf("%c",r[j]+'0');
if (i != t-1) //输出比较坑爹,一点要这样,不然会PE
printf("\n\n");
else
printf("\n");
}
return 0;
}