Pagini recente » Cod sursa (job #1372965) | Cod sursa (job #1095682) | Cod sursa (job #3246112) | Cod sursa (job #509422) | Cod sursa (job #777474)
Cod sursa(job #777474)
#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;
}