You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
653 B
28 lines
653 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
const int N = 100010;
|
|
|
|
int a[N], b[N];
|
|
int al, bl;
|
|
void add(int a[], int &al, int b[], int &bl) {
|
|
int t = 0;
|
|
al = max(al, bl);
|
|
for (int i = 0; i < al; i++) {
|
|
t += a[i] + b[i];
|
|
a[i] = t % 10;
|
|
t /= 10;
|
|
}
|
|
if (t) a[al] = 1;
|
|
while (al > 0 && a[al] == 0) al--;
|
|
}
|
|
|
|
int main() {
|
|
string x, y;
|
|
cin >> x >> y;
|
|
for (int i = x.size() - 1; i >= 0; i--) a[al++] = x[i] - '0';
|
|
for (int i = y.size() - 1; i >= 0; i--) b[bl++] = y[i] - '0';
|
|
add(a, al, b, bl);
|
|
for (int i = al; i >= 0; i--) printf("%d", a[i]);
|
|
return 0;
|
|
} |