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

using namespace std;

int main()
{
    string a, b, c = "";
    cin >> a >> b;

    c.resize(max(a.size(), b.size()) + 1, '0');
    
    int reminder = 0;

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

    while(a.size() > b.size()) b.push_back('0');
    while(a.size() < b.size()) a.push_back('0');

    for(int i = 0; i < max(a.size(), b.size()); i++)
    {
        c[i] = (a[i] + b[i] + reminder - 2*(int)'0') % 10 + '0';
        reminder = (a[i] + b[i] + reminder - 2*(int)'0') / 10;
    }

    if(reminder != 0) c[c.size() - 1] = reminder + '0';
    else c.pop_back();

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

    cout << c;

    return 0;
}