-
Notifications
You must be signed in to change notification settings - Fork 0
/
b10757_2.cpp
43 lines (35 loc) · 711 Bytes
/
b10757_2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
using namespace std;
int arr1[100001];
int arr2[100001];
int arr[100001];
int len;
int main() {
string a, b;
cin >> a >> b;
for (int i = a.length() - 1; i >= 0; i--) {
arr1[a.length() - 1 - i] = a[i] - '0';
}
for (int i = b.length() - 1; i >= 0; i--) {
arr2[b.length() - 1 - i] = b[i] - '0';
}
if (a.length() > b.length()) {
len = a.length();
} else {
len = b.length();
}
for (int i = 0; i < len; i++) {
arr[i] = arr1[i] + arr2[i] + arr[i];
if (arr[i] >= 10) {
arr[i + 1]++;
arr[i] -= 10;
}
}
if (arr[len] != '0') {
cout << arr[len];
}
for (int i = len - 1; i >= 0; i--) {
cout << arr[i];
}
return 0;
}