转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents
#include<cstdio> #include<cstring> void fan(char s[]) { char t; int i,j; for(i = 0,j = strlen(s)-1;i <= j;i++,j--) { t=s[i];s[i]=s[j];s[j]=t; } } int main() { int i,j,n,p=0,g=0,h=1,k,l; char x[1000],y[1000],z[1000]; while(scanf("%d",&n)!=EOF) { while(n--) { p=0; if(g) printf("\n"); g=1; scanf("%s%s",x,y); fan(x);fan(y); k=strlen(x); l=strlen(y); for(i = 0;i < k || i<l;i++ ) { if(i < k && i < l ) z[i]=x[i]+y[i]+ p-'0'; else if(i < k && i >= l) z[i]=x[i]+p; else if(i >= k && i < l) z[i]=y[i]+p; if(z[i]>'9') { z[i]-=10; p=1; } else p=0; } if(p) z[i++]='1'; z[i]='\0'; fan(x);fan(y);fan(z); printf("Case %d:\n",h++); printf("%s + %s = %s\n",x,y,z); } } return 0; }
原文地址:http://blog.csdn.net/u012860063/article/details/36903491