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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    string a, b, res;
    cin >> a >> b;
    res.resize(max(size(a), size(b)));

    bool shift = false;
    int respos = 0, apos = 0, bpos = 0;
    while (apos < size(a) || bpos < size(b)) {
        int digit = shift ? 1 : 0;
        shift = false;
        if (apos < size(a)) {
            digit += a[size(a) - ++apos] - '0';
        }
        if (bpos < size(b)) {
            digit += b[size(b) - ++bpos] - '0';
        }
        if (digit > 9) {
            digit -= 10;
            shift = true;
        }
        res[size(res) - ++respos] = '0' + digit;
    }
    if (shift) cout << '1';
    cout << res << endl;
}