#ifndef _ADD_H_
#define _ADD_H_
#include <iostream>
#include <stack>
#include <string>
using namespace std;
class BigNum;
ostream &operator<<(ostream &os, BigNum &bn);
istream &operator>>(istream &is, BigNum &bn);
BigNum &operator+(BigNum &la, BigNum &ra);
class BigNum
{
stack<char> value;
public:
BigNum(const BiugNum &bn)
{
this->value = bn.value;
}
friend ostream &operator<<(ostream &os, BigNum &bn);
friend istream &operator>>(istream &is, BigNum &bn);
friend BigNum &operator+(BigNum &la, BigNum &ra);
};
ostream &operator<<(ostream &os, BigNum &bn)
{
stack<char> temp(bn.value), out;
while(temp.size()>0)
{
out.push(temp.top());
temp.pop();
};
while(out.size()>0)
{
os << out.top();
out.pop();
};
return os;
}
istream &operator>>(istream &is, BigNum &bn)
{
string temp;
is >> temp;
int s = temp.size();
string::iterator it = temp.begin();
for(;it<temp.end();it++)
{
bn.value.push(*it);
}
return is;
}
bool addChar(char a, char b, char &c,int i)
{
char t;
c = a+b-'0'+i;
if((t=c-'9')>0)
{
c = c - 9;
return true;
}
else
{
return false;
}
}
BigNum operator+(BigNum &la, BigNum &ra)
{
bool b;
BigNum resualt;
stack<char> ta, tb, tr;
char a, b;
int i=0, j;
la.value().size>ra.value.size()?
{ta=la.value;tb=ra.value}:{ta=ra.value;tb=la.value}
while(ta.size())
{
if(tb.size())
i = addChar(ta.top(),tb.top(),a,i)?1:0;
else
i = addChar(ta.top(),'0',a,i)?1:0;
ta.pop();
tb.pop();
tr.push(a);
}
if(i)
tr.push('1');
while(tr.size())
{
resualt.value.push(tr.top());
tr.pop();
}
return resualt;
}
#endif //_ADD_H_