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;

int main() {
    int a[5001], b[5001], result[5001], j;
    fill_n(a, 5001, 0);
    fill_n(b, 5001, 0);
    string input;
    
    cin >> input;
    j = 5000;
    for (int i=input.size()-1; i>=0; i--) {
        a[j] = (int)input[i] - 48;
        j--;
    }
    cin >> input;
    j = 5000;
    for (int i=input.size()-1; i>=0; i--) {
        b[j] = (int)input[i] - 48;
        j--;
    }

    bool shift = 0;
    for (int i=5000; i>=0; i--) {
        result[i] = a[i] + b[i] + shift;
        if (result[i] > 9) {
            result[i] -= 10;
            shift = 1;
        }
        else
            shift = 0;
    }
    bool first = 0;
    for (int i=0; i<5001; i++) {
        if (result[i])
            first = 1;
        if (first)
            cout << result[i];
    }
}