#include
#include
#include
#include
using namespace std;
const int MAX = 110;
class CHugeInt {
private:
int val = 0;
char str[210];
int num[210];
int len;
public:
CHugeInt(){}
CHugeInt(int n)
{
val = n;
memset(str,0,210*sizeof(char));
memset(num,0,210*sizeof(int));
len = 0;
while(n != 0)
{
num[len] = n%10;
len ++;
n /= 10;
}
}
CHugeInt(const char * ch)
{
memset(num,0,210*sizeof(int));
memset(str,0,210*sizeof(char));
strcpy(str,ch);
len = strlen(str);
for(int i = 0; i < len; i ++)
num[i] = (int)(str[len-1-i] - 48);
}
~CHugeInt(){}
friend CHugeInt operator+(const CHugeInt & a,const CHugeInt & b) //MDZZ!!我自己都不知道是怎么编出来的...
{
CHugeInt oth;
int length = a.len;
length += 1; //考虑到进位情况
oth.len = length;
for(int k = 0; k < 210; k ++)
oth.num[k] = 0;
for( int i = 0; i < oth.len; i ++)
{
oth.num[i] += a.num[i] + b.num[i];
oth.num[i+1] += oth.num[i] / 10;
oth.num[i] = oth.num[i] % 10;
}
while((oth.len > 1) && (oth.num[oth.len-1] == 0))
oth.len --;
//神TM知道为什么要有下一步??!!
/* int k = 0;
for( int i = 0; i < oth.len; i ++)
oth.str[k ++] = (char)(oth.num[oth.len-1-i] + 48);
*/ return oth;
}
friend CHugeInt operator+(const int n,const CHugeInt & a) //为什么不能返回引用?
{
CHugeInt c;
int length = a.len;
length ++;
c.len = length;
int temp = n, i = 0;
for(int k = 0; k < 210; k ++)
c.num[k] = 0;
while(temp)
{
c.num[i] = temp%10;
i ++;
temp /= 10;
}
for(int j = 0; j < c.len; j ++)
{
c.num[j] += a.num[j];
c.num[j+1] += c.num[j] / 10;
c.num[j] = c.num[j] % 10;
}
while(c.len > 1 && c.num[c.len - 1] == 0) c.len --;
/* int k = 0;
for( int i = 0; i < c.len; i ++)
c.str[k ++] = (char)(c.num[c.len-1-i] + 48);
/ return c;
}
friend CHugeInt operator+(const CHugeInt &a, const int n)
{
CHugeInt c;
int length = a.len;
length ++;
c.len = length;
int temp = n, i = 0;
for(int k = 0; k < 210; k ++)
c.num[k] = 0;
while( temp)
{
c.num[i] += temp % 10;
i ++;
temp /= 10;
}
for(int j = 0; j < c.len; j ++)
{
c.num[j] += a.num[j];
c.num[j+1] += c.num[j] / 10;
c.num[j] = c.num[j] % 10;
}
while( c.len > 1 && c.num[c.len-1] == 0) c.len --;
/ int k = 0;
for( int i = 0; i < c.len; i ++)
c.str[i] = (char)( c.num[c.len-1-i] + 48);
*/ return c;
}
CHugeInt & operator+=(int n)
{
val += n;
return *this;
}
CHugeInt & operator++()
{
++val;
return *this;
}
CHugeInt operator++(int n) //此处一般不返回引用
{
CHugeInt ss = *this;
val ++;
return ss;
}
friend ostream & operator<<(ostream & out, const CHugeInt & c)
{
if(c.val == 0){
for( int i = c.len-1;i >= 0; i --)
out << c.num[i];
return out;}
else {
// cout << c.val;
out << c.val;
return out;}
}
};
int main()
{
char s[210];
int n;
while (cin >> s >> n) {
CHugeInt a(s);
CHugeInt b(n);
cout << a + b << endl;
cout << n + a << endl;
cout << a + n << endl;
b += n;
cout << ++ b << endl;
cout << b++ << endl;
cout << b << endl;
}
return 0;
}