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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// #include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

void solve()
{
}

int main()
{
    FAST;

    string s1,
        s2;
    cin >> s1 >> s2;
    // s1 bigger
    string tmp;
    if (s2.size() > s1.size())
    {
        tmp = s1;
        s1 = s2;
        s2 = tmp;
    }

    int memory = 0;
    int value;
    stack<int> ss;
    for (int i1 = s1.size() - 1, i2 = s2.size() - 1; i1 >= 0; i1--, i2--)
    {
        value = s1[i1] - '0' + memory;
        if (i2 >= 0)
        {
            value += s2[i2] - '0';
        }

        if (value >= 10)
        {
            memory = 1;
            ss.push(value - 10);
        }
        else
        {
            memory = 0;
            ss.push(value);
        }
    }
    if (memory > 0)
    {
        ss.push(1);
    }

    for (; ss.size() != 0;)
    {
        cout << ss.top();
        ss.pop();
    }
}