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
#include <stdio.h>

#define MAX 5000

int main()
{
char sA[MAX+1],sB[MAX+1];
int a,b,c,r,A[MAX],B[MAX],R[MAX+1],d;

	scanf("%s\n",sA);
	scanf("%s\n",sB);

	a = 0;
	while (sA[a]) 
	{
		A[a] = sA[a]-'0';
		a++;
	}
	b = 0;
	while (sB[b]) 
	{
		B[b] = sB[b]-'0';
		b++;
	}
	
	r = 0;
	c = 0;
	while (r < a || r < b)
	{
		d = (a-r>0?A[a-r-1]:0) + (b-r>0?B[b-r-1]:0) + c;
		R[r] = d % 10;
		c = d / 10;
//		printf("a=%d, b=%d, c=%d, A[]=%d, B[]=%d, d=%d\n",a,b,c,a-r>0?A[a-r-1]:0,b-r>0?B[b-r-1]:0,d);
		r++;
	}
	if (c > 0) R[r] = c; else r--;
	
	while (r >= 0)
	{
		printf("%d",R[r]);
		r--;
	}
	
	return 0;
}