Cod sursa(job #792631)

Utilizator 10iCNMVNume Complet 10iCNMV Data 28 septembrie 2012 11:50:46
Problema A+B Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <stdio.h>
#include <cstdlib>
#include <cstring>

using namespace std;

int a[20],b[20];

int main()
{
	char s[20];
	freopen("adunare.in","r",stdin);
	freopen("adunare.out","w",stdout);
	char c;
	int x = 0, y = 0, i, t = 0;
	/*do
	{
		scanf("%c",&c);
		a[ ++ x] = c - '0';
	}
	while (c != '\n');
	while(scanf("%c",&c) != EOF	)
	{
		a[++y] = c - '0';
	}*/
	
	scanf ("%s\n", s);
	x = strlen (s);
	
	for (i = x - 1; i >= 0; i --)
		a[ ++ a[0] ] = s[i] - 48;
	
	scanf ("%s", s);
	x = strlen (s);
	
	for (i = x - 1; i >= 0; i --)
		b[ ++ b[0] ] = s[i] - 48;
	
	for (i = 1; i <= a[0] || i <= b[0]; i ++, t /= 10)
		a[i] = (t += a[i] + b[i]) % 10;
	a[0] = i - 1;
	
	for (i = a[0]; i; i --)
		printf ("%d", a[i]);
	
	return 0;
	
}