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
#include <cstdio>
#include <cstdlib>
#include <cstring>

char a[5002];
char b[5002];
char c[5002];

#ifdef	DEBUG
#define	DBG(x)	(x)
#else
#define	DBG(x)
#endif

int main(void)
{
	int al, bl;
	int ai, bi, ci, ov;

	a[0] = b[0] = '0';
	fgets(a + 1, sizeof(a) - 1, stdin);
	fgets(b + 1, sizeof(a) - 1, stdin);

	al = strlen(a + 1) - 1;
	bl = strlen(b + 1) - 1;

	c[sizeof(c) - 1] = 0;
	for (ai = al, bi = bl, ci = sizeof(c) - 2, ov = 0; ai >= 0 || bi >= 0; ai--, bi--, ci--) {
		int x = ov;
		if (ai >= 0)
			x += a[ai] - '0';
		if (bi >= 0)
			x += b[bi] - '0';
		//fprintf(stderr, "a[%d]=%c b[%d]=%c x=%d\n", ai, a[ai], bi, b[bi], x);
		ov = x >= 10;
		if (ov)
			x -= 10;
		c[ci] = x + '0';
	}

	c[ci] = ov + '0';
	while (c[ci] == '0')
		ci++;
	puts(c + ci);

	return 0;
}