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
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
#include <iostream>

using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);

    string a, b;
    int dl1, dl2;
    short liczba;
    short zapas = 0;

    cin >> a >> b;

    if (a.size() > b.size())
    {
        dl1 = (int)a.size() - 1;
        dl2 = (int)b.size() - 1;

        while (dl2 >= 0)
        {
            liczba = (short)(a[dl1] - '0') + (short)(b[dl2] - '0') + zapas;

            if (liczba > 9)
                zapas = 1;
            else
                zapas = 0;
            
            a[dl1] = (char)(liczba % 10 + '0');

            --dl1;
            --dl2;
        }

        if (zapas)
        {
            while (dl1 >= 0 && zapas)
            {
                if (a[dl1] == '9')
                    a[dl1] = '0';
                else
                {
                    zapas = 0;
                    a[dl1] = (char)((short)a[dl1] + 1);
                }
                --dl1;
            }

            if (zapas)
                cout << '1';
        }
        cout << a << '\n';
    }
    else
    {
        dl1 = (int)a.size() - 1;
        dl2 = (int)b.size() - 1;

        while (dl1 >= 0)
        {
            liczba = (short)(a[dl1] - '0') + (short)(b[dl2] - '0') + zapas;

            if (liczba > 9)
                zapas = 1;
            else
                zapas = 0;

            b[dl2] = (char)(liczba % 10 + '0');

            --dl1;
            --dl2;
        }

        if (zapas)
        {
            while (dl2 >= 0 && zapas)
            {
                if (b[dl2] == '9')
                    b[dl2] = '0';
                else
                {
                    zapas = 0;
                    b[dl2] = (char)((short)b[dl2] + 1);
                }
                --dl2;
            }

            if (zapas)
                cout << '1';
        }
        cout << b << '\n';
    }



    return 0;
}