标签:
#include"iostream" #include"stdio.h" #include"stdlib.h" #include"string.h" using namespace std; char c[1000]; void sum(char a[],char b[]){ int al=strlen(a)-1; int bl=strlen(b)-1; int cl=0; while(al>=0&&bl>=0){ c[cl]+=a[al]+b[bl]-‘0‘*2; c[cl+1]+=c[cl]/10; c[cl]=c[cl]%10; al--;bl--;cl++; } while(al>=0){ c[cl]+=a[al]-‘0‘; c[cl+1]+=c[cl]/10; c[cl]=c[cl]%10; al--;cl++; } while(bl>=0){ c[cl]+=b[bl]-‘0‘; c[cl+1]+=c[cl]/10; c[cl]=c[cl]%10; bl--;cl++; } if(c[cl]==0)cl--; for(int i=0;i<=cl;i++)printf("%c",c[cl-i]+‘0‘); printf("\n"); } int main(){ char a[1000],b[1000]; int ti; scanf("%d",&ti); for(int i=1;i<=ti;i++){ cin>>a>>b; memset(c,0,1000); printf("Case %d:\n%s + %s = ",i,a,b); sum(a,b); if(i!=ti)printf("\n"); } }
标签:
原文地址:http://www.cnblogs.com/lyqatdl/p/4713037.html