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

/**
 * @Author: Robert Rośczak LO nr. 1 w Łodzi.
 * @Problem: A+B (apb)
*/

int main() {
    string str1, str2, res = "";
    cin >> str1 >> str2;

    if (str1.length() > str2.length()) swap(str1, str2);
    int isCool = 0;

    reverse(str1.begin(), str1.end());
    reverse(str2.begin(), str2.end());

    for (int i = 0; i < str1.length(); i++) {
        int sum = ((str1[i] - '0') + (str2[i] - '0') + isCool);
        res.push_back(sum % 10 + '0');
        isCool = sum / 10;
    }
    for (int i = str1.length(); i < str2.length(); i++) {
        int sum = ((str2[i] - '0') + isCool);
        res.push_back(sum % 10 + '0');
        isCool = sum / 10;
    }

    if (isCool) res.push_back(isCool + '0');
    reverse(res.begin(), res.end());
    cout << res;

    return 0;
}