Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 124589 Accepted Submission(s): 23993
ios
1 #include <iostream> 2 using namespace std; 3 4 void sum(char (&a)[1001],char (&b)[1001]); 5 int main() 6 { 7 int T, count_T; 8 char a[1001], b[1001]; 9 cin >> T; 10 for(count_T=1; count_T <= T; count_T++) 11 { 12 cin >> a >> b; 13 14 if(count_T==1) 15 { 16 cout << "Case " << count_T << ":" << endl; 17 } 18 else 19 { 20 cout << "\nCase " << count_T << ":" << endl; 21 } 22 23 cout << a << " + " << b << " = "; 24 25 sum(a,b); 26 } 27 return(0); 28 } 29 void sum(char (&a)[1001],char (&b)[1001]) 30 { 31 char c[1002]; 32 int la, lb; 33 la=strlen(a)-1; 34 lb=strlen(b)-1; 35 int i; 36 int flag=0; 37 for(i=0;la>=0 && lb>=0;la--,lb--,i++) 38 { 39 flag+=(a[la]-'0')+(b[lb]-'0'); 40 c[i]=flag%10; 41 flag/=10; 42 } 43 for(la=la;la>=0;la--,i++) 44 { 45 flag+=(a[la]-'0'); 46 c[i]=flag%10; 47 flag/=10; 48 } 49 for(lb=lb;lb>=0;lb--,i++) 50 { 51 flag+=(b[lb]-'0'); 52 c[i]=flag%10; 53 flag/=10; 54 } 55 if(flag) 56 { 57 c[i]=flag; 58 i++; 59 } 60 for(i--;i>=0;i--) 61 { 62 cout<<(char)(c[i]+'0'); 63 } 64 cout<<endl; 65 }