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
// APB.cpp : Defines the entry point for the application.
//

#include <iostream>

using namespace std;

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

	const int MAXS = 5000;
	string a, b;
	cin >> a >> b;
	int ia = a.length() - 1;
	int ib = b.length() - 1;
	int ic = MAXS;
	int c[MAXS+1] = { 0 };

	int digit = 0;
	do
	{
		digit += c[ic] + (ia >= 0 ? a[ia] - '0' : 0) + (ib >= 0 ? b[ib] - '0' : 0);
		c[ic] = digit % 10;
		digit /= 10;
		ia--;
		ib--;
		ic--;
	}
	while (ic>=0 && (ia>=0 || ib>=0));
	if (digit && ic >= 0) c[ic] = digit;

	bool started = false;
	for (int i = 0; i <= MAXS; i++)
	{
		if (c[i] != 0 || started)
		{
			cout << c[i];
			started = true;
		}
	}
	if (!started) cout << 0;

	return 0;
}