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
#include <bits/stdc++.h>

using namespace std;

string a, b;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>a>>b;
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());

    while (b.size() < a.size()) b.push_back('0');
    while (a.size() < b.size()) a.push_back('0');
    a+="0", b+="0";

    int c=0, sz=a.size();

    vector<int> v;
    for (int i=0; i<sz; ++i) {
        int res=(a[i]-'0')+(b[i]-'0')+c;
        c=res/10;

        v.push_back(res%10);
    }

    if (c > 0) v.push_back(c);
    while (!v.empty()) {
        if (v.back() == 0) v.pop_back();
        else break;
    }

    reverse(v.begin(), v.end());

    for (auto u : v) cout<<u;
    cout<<"\n";
}