#include<stdio.h>
#include<string.h>
int main()
{
char d[1005],e[1005];
int c[1005],len1,len2,p,q,m,a[1005],b[1005];
int i,j,k,n;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%s%s",d,e);
memset(c,0,sizeof(c));
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
len1=strlen(d);
len2=strlen(e);
for(j=0;j<len1;j++)
a[j]=d[len1-1-j]-'0';
for(j=0;j<len2;j++)
b[j]=e[len2-1-j]-'0';
p=len1<len2?len1:len2;//最小值
q=len1>len2?len1:len2;//最大值
for(j=0;j<p;j++)
{
c[j]=a[j]+b[j];
}
for(j=0;j<p-1;j++)
{
if(c[j]>9)
{
c[j+1]=c[j+1]+c[j]/10;
c[j]=c[j]%10;
}
}
for(j=p;j<q;j++)
{
if(len1>len2)
c[j]=a[j];
else
c[j]=b[j];
}
for(j=p-1;j<q;j++)
{
if(c[j]>9)
{
c[j+1]=c[j+1]+c[j]/10;
c[j]=c[j]%10;
}
}
if(c[q])//判断最后一位是否进位
q++;
printf("Case %d:\n%s + %s = ",i+1,d,e);
for(j=q-1;j>=0;j--)
printf("%d",c[j]);
printf("\n");
if(n!=1&&i+1<n)
printf("\n");
}
}
本题主要是倒置后相加如123+456789
换成321才a[0]=3,a[1]=2....另一个换成987654b[0]=9,b[1]=8....相加后进位