Cod sursa(job #777474)

Utilizator Stefex09Stefan Teodorescu Stefex09 Data 12 august 2012 14:18:57
Problema A+B Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.14 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 &);
	
	friend istream& operator >> (istream &in, HugeInt &H){
		int x;
		in >> x;
		
		while (x){
			H[ ++ H[0] ] = x % BASE;
			x /= BASE;
		}
		
		return in;
	}
	
	friend ostream& operator << (ostream &out, HugeInt &H){
		while (H[0])
			out << H[ H[0] --];
		
		return out;
	}
};

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;
}

int main ()
{
	HugeInt X, Y;
	
	in >> X >> Y;
	X += Y;
	out << X;
	
	return 0;
}