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

using namespace std;

int main()
{
    string a, b;
    string r = "";
    getline(cin, a);
    getline(cin, b);

    int i = a.length() - 1;
    int j = b.length() - 1;
    int c = 0;
    int sum = 0;

    while (i >= 0 || j >= 0)
    {
        int na = i >= 0 ? int(a[i] - '0') : 0;
        int nb = j >= 0 ? int(b[j] - '0') : 0;
        sum = na + nb + c;
        c = 0;
        if (sum > 9) {
            c = 1;
            sum -= 10;
        }
        r += to_string(sum);
        i--;
        j--;
    }
    
    if (c == 1) 
    {
        r += '1';
    }
    reverse(r.begin(), r.end());

    cout << r;
}