标签:
1 #include<cstring> 2 #include<cstdio> 3 using namespace std; 4 5 int main() 6 { 7 //freopen("in.txt","r",stdin); 8 int count,temp; 9 int a1[1010],a2[1010]; 10 char s1[1010],s2[1010]; 11 int t,i,j,len1,len2; 12 scanf("%d",&count); 13 t=1; 14 while(count--) 15 { 16 printf("Case %d:\n",t++); 17 memset(a1,0,sizeof(a1)); 18 memset(a2,0,sizeof(a2)); 19 scanf("%s%s",s1,s2); 20 printf("%s + %s = ",s1,s2); 21 int len1=strlen(s1); 22 int len2=strlen(s2); 23 for(i=len1-1,j=0;i>=0;i--) 24 a1[j++]=s1[i]-‘0‘; 25 for(i=len2-1,j=0;i>=0;i--) 26 a2[j++]=s2[i]-‘0‘; 27 int maxlen=len1>len2?len1:len2; 28 for(i=0;i<maxlen;i++) 29 { 30 a1[i]+=a2[i]; 31 if(a1[i]>=10) 32 { 33 a1[i+1]+=1; 34 a1[i]-=10; 35 } 36 } 37 for(j=1009;j>=0;j--) 38 if(a1[j])break; 39 if(j==-1) 40 printf("0"); 41 for(;j>=0;j--) 42 printf("%d",a1[j]); 43 printf("\n"); 44 if(count!=0) 45 printf("\n"); 46 } 47 return 0; 48 }
标签:
原文地址:http://www.cnblogs.com/homura/p/4672761.html