10: Big integer addition, 10: integer addition
10: large integer addition
- View
- Submit
- Statistics
- Question
-
Total time limit:
-
1000 ms
-
Memory limit:
-
65536kB
-
Description
-
Calculate the sum of two non-negative integers not greater than 200 BITs.
-
Input
-
There are two rows. Each row is a non-negative integer of no more than 200 BITs, and there may be redundant leading 0.
-
Output
-
A row, that is, the result after adding. There cannot be any redundant leading 0 in the result, that is, if the result is 342, the output cannot be 0342.
-
Sample Input
-
2222222222222222222233333333333333333333
-
Sample output
-
55555555555555555555
-
Source
-
Programming Practice 2007
-
1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 using namespace std; 5 char a [100001]; 6 char B [100001]; 7 char c [100001]; 8 int a1 [100001]; 9 int b1 [100001]; 10 int c1 [100001]; 11 int main () 12 {13 scanf ("% s", & a); 14 scanf ("% s", & B); 15 int la = strlen (); 16 int lb = strlen (B); 17 for (int I = 0; I <la; I ++) 18 a1 [I] = a [la-i-1]-'0 '; 19 for (int I = 0; I <lb; I ++) 20 b1 [I] = B [lb-i-1]-'0'; 21 int x = 0; // carry 22 int I = 0; // The number of digits in the result is 23 while (I <la | I <lb) 24 {25 c1 [I] = a1 [I] + b1 [I] + x; 26 x = c1 [I]/10; 27 c1 [I] = c1 [I] % 10; 28 I ++; 29} 30 c1 [I] = x; 31 while (1) 32 {33 if (c1 [I] = 0 & I> = 1) 34 I --; 35 else break; 36} 37 38 for (int j = I; j> = 0; j --) 39 cout <c1 [j]; 40 return 0; 41}