标签:
1 #include <iostream> 2 #include <cstring> 3 4 using namespace std; 5 6 char a[1002],b[1002]; 7 int s[1004]; 8 int shu(char p) 9 { 10 return p-‘0‘; 11 } 12 int main() 13 { 14 int lena,lenb; 15 int n; 16 cin >> n; 17 while(n--) 18 { 19 cin >> a >> b; 20 lena = strlen (a); lenb = strlen (b); 21 int max = lena > lenb ? lena : lenb; 22 int t=max; 23 for(int i=0;i<=max;i++) 24 s[i]=0; 25 while(lena&&lenb) 26 { 27 lena -- ; 28 lenb -- ; 29 s[t]=shu(a[lena])+shu(b[lenb]); 30 s[t-1]=s[t]/10; 31 s[t]%=10; 32 t--; 33 } 34 while(lena>0) 35 { 36 s[t]+=shu(a[--lena]) ; 37 s[t-1]=s[t]/10; 38 s[t]=s[t]%10; 39 t--; 40 } 41 while(lenb>0) 42 { 43 s[t]+=shu(b[--lenb]) ; 44 s[t-1]=s[t]/10; 45 s[t]=s[t]%10; 46 t--; 47 } 48 int i; 49 for(i=0;i<=max;i++) 50 { 51 if(s[i]!=0) 52 break; 53 //cout << s[i] ; 54 } 55 for(i;i<=max;i++) 56 cout <<s[i]; 57 cout << endl; 58 59 } 60 return 0; 61 }
标签:
原文地址:http://www.cnblogs.com/WDKER/p/5475175.html