Cod sursa(job #777260)

Utilizator Stefex09Stefan Teodorescu Stefex09 Data 11 august 2012 18:07:32
Problema A+B Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <iostream>
#include <fstream>
#include <vector>
#define A (*this)

using namespace std;

ifstream in ("adunare.in");
ofstream out ("adunare.out");

class HugeInt : protected vector <int> 
{
private:
	static const int BASE = 10;
	static const int MAXN = 300;
	
public:
	
	HugeInt ();
	HugeInt (int);
	
	void operator += (HugeInt &);
	void afisare ();
};

HugeInt :: HugeInt ()
{
	this -> resize (MAXN);
	
	for (int i = 0; i < MAXN; ++ i)
		A[i] = 0;
}

HugeInt :: HugeInt (int X)
{
	this -> resize (MAXN);
	
	for (A[0] = 0; X; X /= BASE)
		A[ ++ A[0] ] = X % BASE;
}

void HugeInt :: operator += (HugeInt &B)
{
	int i, t = 0;
	
	for (i = 1; i <= A[0] || i <= B[0] || t; i ++, t /= BASE)
		A[i] = (t += A[i] + B[i]) % BASE;
	
	A[0] = i - 1;
}

void HugeInt :: afisare ()
{
	for (int i = A[0]; i; -- i)
		out << A[i];
}

int main ()
{
	int X, Y;
	
	in >> X >> Y;
	
	HugeInt M (X), N (Y);
	M += N;
	M.afisare ();
	
	return 0;
}