#include<stdio.h>#include<string.h>int main(){ char a[1000],b[1000],c[1001]; int d,f,g,h,j,i,k,l,m; int alenth,blenth,carry,clenth; scanf("%d",&k); for(i=1;i<=k;i++) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); scanf("%s %s",&a,&b); alenth=strlen(a); blenth=strlen(b); clenth=(alenth>blenth)?alenth:blenth; for(j=alenth-1,l=blenth-1;j>=0&&l>=0;j--,l--) { if(a[j]-'0'+b[l]-'0'+carry>9) { c[clenth--]=(a[j]-'0'+b[l]-'0'+carry)%10+'0'; carry=1; } else { c[clenth--]=(a[j]-'0'+b[l]-'0'+carry)%10+'0'; carry=0; } } while(j>=0) { c[clenth--]=(a[j--]-'0'+carry)%10+'0'; if(a[j--]-'0'+carry>9) carry=1; else carry=0; } while(l>=0) { c[clenth--]=(b[l--]-'0'+carry)%10+'0'; if(b[l--]-'0'+carry>9) carry=1; else carry=0; } c[0]=carry+'0'; g=0; while(c[g]=='0') g++; if(c[g]!='\0') printf("Case %d:\n%s + %s = %s\n",i,a,b,c+g); else printf("Case %d:\n%s + %s = %s\n",i,a,b,c+g-1); if(i!=k) printf("\n"); carry=0; }return 0;}
目前暂无任何回答
- 0 回答
- 0 关注
- 986 浏览
添加回答
举报
0/150
提交
取消