标签:ESS some you bottom res ssi put -- esc
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 429408 Accepted Submission(s): 83462
2 1 2 112233445566778899 998877665544332211
Case 1: 1 + 2 = 3 Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110
1 #include<iostream> 2 #include<cstring> 3 #include<string> 4 using namespace std; 5 string bigAdd(string num1, string num2) { 6 7 string res; 8 if (num1.size() == 0) { 9 res = num2; 10 return res; 11 } 12 if (num2.size() == 0) { 13 res = num1; 14 return res; 15 } 16 17 res = ""; 18 int n1 = num1.size()-1, n2 = num2.size()-1; 19 int carry = 0; 20 while (n1 >= 0 || n2 >= 0) { 21 22 int a = n1 >= 0 ? num1[n1--] - ‘0‘ : 0; 23 int b = n2 >= 0 ? num2[n2--] - ‘0‘ : 0; 24 25 int t = carry + a + b; 26 carry = t / 10; 27 t = t % 10; 28 res = to_string(t) + res; 29 } 30 //判断是否还有进位 31 while (carry) { 32 int t = carry / 10; 33 carry %= 10; 34 res = to_string(carry) + res; 35 carry = t; 36 } 37 return res; 38 } 39 40 int main() { 41 int sum=0,count; 42 cin>>count; 43 if(count>=1&&count<=20) { 44 string a[22][2]; 45 for(int i=0; i<count; i++) { 46 cin>>a[i][0]>>a[i][1]; 47 } 48 for(int i=0; i<count; i++) { 49 cout<<"Case "<<i+1<<":"<<endl; 50 cout<<a[i][0]<<" + "<<a[i][1]<<" = "<<bigAdd(a[i][0],a[i][1])<<endl; 51 if(i+1!=count) { 52 cout<<endl; 53 } 54 } 55 } 56 return 0; 57 }
标签:ESS some you bottom res ssi put -- esc
原文地址:https://www.cnblogs.com/yangxin6017/p/9505087.html