//name:周恩冉 
//id:89013900 
//hw:(5) 
#include <iostream>
using namespace std;

// 其實這篇不太需要註解了...
// 多半一看就知道在幹嘛, 麻煩的地方就只有模擬筆算的部份...
class BigInt
{
private:
	static const int Max = 100;
	bool sign;
	int np[Max];
public:
	BigInt();
	BigInt(int);
	// 只寫了這兩個 constructor 真抱歉..^^;;

	BigInt operator+= (const BigInt&);
	BigInt operator-= (const BigInt&);
	BigInt operator*= (const BigInt&);
	BigInt operator++ ();
	BigInt operator-- ();
	BigInt operator++ (int);
	BigInt operator-- (int);

	friend bool operator> (const BigInt&, const BigInt&);
	friend bool operator< (const BigInt&, const BigInt&);
	friend bool operator>= (const BigInt&, const BigInt&);
	friend bool operator<= (const BigInt&, const BigInt&);
	friend bool operator== (const BigInt&, const BigInt&);
	friend bool operator!= (const BigInt&, const BigInt&);

	friend BigInt operator+ (const BigInt&, const BigInt&);
	friend BigInt operator- (const BigInt&, const BigInt&);
	friend BigInt operator* (const BigInt&, const BigInt&);

	friend ostream& operator<< (ostream&, const BigInt&);
};

inline BigInt::BigInt()
{
	sign = true;
	for(int i = 0; i < Max; i++)
	{
		np[i] = 0;
	}
}

inline BigInt::BigInt(int x)
{
	int i;
	sign = (x < 0)? false: true;
	x = abs(x);
	for(i = 0; x; i++)
	{
		np[i] = x % 10;
		x /= 10;
		// 每次取個位數字, 取完再向右移一位
	}
	for(; i < Max; i++)
	{
		np[i] = 0;
	}
}

inline BigInt BigInt::operator+= (const BigInt& x)
{
	return (*this = *this + x);
}

inline BigInt BigInt::operator-= (const BigInt& x)
{
	return (*this = *this - x);
}

inline BigInt BigInt::operator*= (const BigInt& x)
{
	return (*this = *this * x);
}

inline BigInt BigInt::operator++ ()
{
	return (*this += 1);
}

inline BigInt BigInt::operator-- ()
{
	return (*this -= 1);
}

inline BigInt BigInt::operator++ (int)
{
	BigInt temp(*this);
	*this += 1;
	return temp;
}

inline BigInt BigInt::operator-- (int)
{
	BigInt temp(*this);
	*this -= 1;
	return temp;
}

ostream& operator<< (ostream& os, const BigInt& x)
{
	int i;

	for(i = x.Max - 1; i >= 0 && !x.np[i]; i--);
	if(i == -1){
		cout << '0';
		return os;
	}
	os << (x.sign? "": "-");
	for(; i >= 0; i--)
	{
		cout << x.np[i];
	}

	return os;
}

BigInt operator+ (const BigInt& x, const BigInt& y)
{
	int i;
	BigInt z;
	if(x.sign == y.sign){
		// 若同號, 直接相加, 正負號不變
		z.sign = x.sign;
		for(i = 0; i < z.Max - 1; i++)
		{
			z.np[i] += x.np[i] + y.np[i];
			if(z.np[i] >= 10){
				z.np[i + 1]++;
				z.np[i] -= 10;
			}
		}
	}else{
		// 若異號, 取絕對值大的減小的, 正負號同絕對值大者
		for(i = z.Max - 1; i >= 0; i--)
		{
			if(x.np[i] > y.np[i]){
				z.sign = x.sign;
				for(; i >= 0; i--)
				{
					z.np[i] = x.np[i] - y.np[i];
					if(z.np[i] < 0){
						z.np[i + 1]--;
						z.np[i] += 10;
					}
				}
				break;
			}else if(x.np[i] < y.np[i]){
				z.sign = y.sign;
				for(; i >= 0; i--)
				{
					z.np[i] = y.np[i] - x.np[i];
					if(z.np[i] < 0){
						z.np[i + 1]--;
						z.np[i] += 10;
					}
				}
				break;
			}
		}
		// 若 for 結束之前都沒有進到 if else 中, 代表兩者同值異號
		// 相加為 0, 直接 return 即可
	}
	return z;
}

BigInt operator- (const BigInt& x, const BigInt& y)
{
	// x - y = x + (-y)
	BigInt temp(y);
	temp.sign ^= true;
	return (x + temp);
}

BigInt operator* (const BigInt& x, const BigInt& y)
{
	BigInt z;
	int i, j;

	// 模擬手算, 有點小雜...
	// 稍微做了點 check over flow 的動作...
	z.sign = !(x.sign != y.sign);
	for(i = 0; i < z.Max; i++)
	{
		for(j = 0; j < z.Max; j++)
		{
			if(i + j >= z.Max){
				if(x.np[i] * y.np[j]){
					cout << "over flow" << endl;
					exit(0);
				}
			}else{
				z.np[i + j] += x.np[i] * y.np[j];
				if(z.np[i + j] >= 10){
					if(i + j + 1 >= z.Max){
						cout << "over flow" << endl;
						exit(0);
					}else{
						z.np[i + j + 1] += z.np[i + j] / 10;
						z.np[i + j] %= 10;
					}
				}
			}
		}
	}
	return z;
}

bool operator> (const BigInt& x, const BigInt& y)
{
	// 異號可直接比
	if(x.sign && !y.sign){
		return true;
	}else if(y.sign && !x.sign){
		return false;
	}
	// 同號看絕對值與正負號
	for(int i = x.Max - 1; i >= 0; i--)
	{
		if(x.np[i] > y.np[i]){
			return x.sign;
		}else if(x.np[i] < y.np[i]){
			return !x.sign;
		}
	}
	// 相等自然不大於
	return false;
}

bool operator== (const BigInt& x, const BigInt& y)
{
	// 一位一位看
	if(x.sign != y.sign){
		return false;
	}
	for(int i = x.Max - 1; i >= 0; i--)
	{
		if(x.np[i] != y.np[i]){
			return false;
		}
	}
	return true;
}

bool operator< (const BigInt& x, const BigInt& y)
{
	return !((x > y) || (x == y));
}

bool operator>= (const BigInt& x, const BigInt& y)
{
	return ((x > y) || (x == y));
}

bool operator<= (const BigInt& x, const BigInt& y)
{
	return !(x > y);
}

bool operator!= (const BigInt& x, const BigInt& y)
{
	return !(x == y);
}

int main()
{
	return 0;
}

