2 1 2 112233445566778899 998877665544332211
Case 1: 1 + 2 = 3 Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110
#include<stdio.h>
void sub(char a[],char b[]);
main()
{
char a[1000],b[1000];
int n,i;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%s %s",&a,&b);
if(i>0)
printf("/n");
printf("Case %d:/n",i+1);
printf("%s + %s = ",a,b);
sub(a,b);
}
}
void sub(char * a,char * b)
{
int lenA,lenB,i,k,flag=0,r,m;
int c[1001];
for(m=0;m<1001;m++)
c[m]=0;
lenA=strlen(a);lenB=strlen(b);
k=lenA>lenB?lenA:lenB;
r=k;
while(lenA>0&&lenB>0)
{
c[k]=a[lenA-1]+b[lenB-1]+flag-96;
if(c[k]>9)
{
c[k]=c[k]%10;
flag=1;
}
else
{
flag=0;
}
k--;lenA--; lenB--;
}
if(lenA>lenB)
{
for(i=lenA-1;i>=0;i--,k--)
{
c[k]=a[i]-48+flag;
if(c[k]>9)
{
c[k]=c[k]%10;
flag=1;
}
else
{
flag=0;
}
}
}
else if(lenA<lenB)
{
for(i=lenB-1;i>=0;i--,k--)
{
c[k]=b[i]-48+flag;
if(c[k]>9)
{
c[k]=c[k]%10;
flag=1;
}
else
{
flag=0;
}
}
}else
{
if(flag==1)
c[k]=1;
}
if(c[0]==0)
{
for(i=0;i<=r;i++)
{
c[i]=c[i+1];
}
r--;
}
for(i=0;i<=r;i++)
printf("%d",c[i]);
printf("/n");
}