#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
using namespace std;
const int maxn = 1000;
struct bign
{
int len, s[maxn]; //s是逆序存储
bign(){ memset(s, 0 , sizeof(s)); len = 1 ; } //构造函数
bign(int num) { *this = num ; } //初始化
bign(const char* num) { *this = num ; }
string str() const
{
int i;
string res = "";
for( i = 0 ; i < len ; i++ )
res = (char)( s[i] + '0' ) + res ;
if (res == "") res = "0";
return res;
}
bign operator = (const char* num)
{
int i;
len = strlen(num);
for( i = 0 ; i < len ; i++ )
s[i] = num[len-i-1] - '0' ;
return *this;
}
bign operator = (int num)
{
char s[maxn];
sprintf(s , "%d" , num);
*this = s;
return *this;
}
//辅助函数
void clean() { while(len > 1 && !s[len-1]) len--; }
bign operator + (const bign& b) const
{
bign c;
c.len = 0;
int i, g;
for( i = 0 , g = 0 ; g || i < ( len > b.len ? len : b.len ) ; i++ )
{
int x = g ;
if( i < len ) x += s[i] ;
if( i < b.len ) x += b.s[i] ;
c.s[c.len++] = x % 10 ;
g = x / 10 ;
}
c.clean();
return c;
}
bign operator+= (const bign &b)
{
*this = *this + b;
return *this;
}
//比较的前提是两个数都没有前导零
bool operator < (const bign& b) const
{
if( len != b.len ) return len < b.len ;
int i;
for( i = len-1 ; i >= 0 ; i-- )
if( s[i] != b.s[i] ) return s[i] < b.s[i];
return false;
}
bool operator > (const bign& b) const { return b < *this; }
bool operator <= (const bign& b) const { return !(b < *this); }
bool operator >= (const bign& b) const { return !(*this < b); }
bool operator != (const bign& b) const { return b < *this || *this < b; }
bool operator == (const bign& b) const { return !(b < *this) || !(*this < b); }
};
istream& operator >> (istream &in , bign& x)
{
string s;
in >> s;
x = s.c_str();
return in;
}
ostream& operator << (ostream &out , const bign& x)
{
out << x.str();
return out;
}