sicily 1159

#include<iostream>
#include<string.h>

using namespace std;

const int LEN = 101;

class BigInteger
{
public:
	BigInteger();
	BigInteger operator + (BigInteger& rhs);

private:
	char x[LEN + 1];

friend istream& operator >> (istream& in, BigInteger& bi);
friend ostream& operator << (ostream& out, BigInteger& bi);
};

BigInteger::BigInteger()
{
	memset(x,'0',LEN);
	x[LEN] = '\0';
}

BigInteger BigInteger::operator +(BigInteger& rhs)
{
	BigInteger tmp;
	int i;
	int carry = 0;
	for(i = LEN - 1; i >= 0; i--)
	{
		int lx = this->x[i] - '0';
		int rx = rhs.x[i] - '0';
		tmp.x[i] = (lx + rx + carry) % 10 + '0';
		carry = lx + rx + carry  >= 10 ? 1 : 0; 
	}

	return tmp;
}



istream& operator >> (istream& in, BigInteger& bi)
{
	//输入时要清空之前的数据
	memset(bi.x,'0',LEN);
	bi.x[LEN] = '\0';

	char tmp[LEN + 1];
	in >> tmp;
	int len = strlen(tmp);
	memcpy(bi.x + LEN - len , tmp, len);
	
	return in;
}

ostream& operator << (ostream& out, BigInteger& bi)
{

	int i = 0;
	while(bi.x[i] == '0')
	{
		i++;
	}
	if(i == LEN + 1)
		out << "0" << endl;
	else
	{
		out << bi.x + i << endl;
	}
	return out;
}


BigInteger bi[10000];

int main()
{
	int N;
	//BigInteger bi[10000];
	int i;

	while(cin >> N)
	{
		BigInteger sum;
		for(i = 0; i < N; i++)
		{
			cin >> bi[i];
			sum = sum + bi[i];
		}

		cout << sum;

	}

	return 0;
}

你可能感兴趣的:(BI,Class)