#include #include const bool debugging = false; const int size = 2000; // I want to make it easy to work with. // Change to something big later. class bignum { public: int digit[size]; char sign; // '+' or '-' bool ok; bignum(); void init(); void addsmall_is(int N); void mulsmall_is(int N); void become(int N); void become(string N); }; // to store the number one thousand six hundred and seventy nine, // 1679, digit[0]=9, digit[1]=7, digit[2]=6, digit[3]=1, all the rest are zero void bignum::init() { for (int i = 0; i < size; i += 1) digit[i] = 0; sign = '+'; ok = true; } bignum::bignum() { init(); } ostream & operator<<(ostream & out, const bignum & B) { if (! B.ok) out << "BAD"; out << B.sign; bool printed = false; for (int i = size - 1; i >= 0; i -= 1) { int dig = B.digit[i]; if (debugging) out << "|"; if (dig != 0 || printed || debugging) { out << dig; printed = true; } } if (! printed) out << "0"; return out; } void bignum::addsmall_is(int N) // _is means "ignoring the + or - sign" // N must be small. { int toadd = N; int position = 0; while (toadd > 0) { int sum = digit[position] + toadd; if (sum < 10) { digit[position] = sum; toadd = 0; } else { digit[position] = sum % 10; toadd = sum / 10; } position += 1; if (position >= size) { ok = false; break; } } } void bignum::mulsmall_is(int N) // _is means "ignoring the + or - sign" // N must be small. { int carry = 0; for (int position=0; position> c; if (c == '=') { string s; cin >> s; if (cin.fail()) break; X.become(s); } else { int n; cin >> n; if (c == '+') X.addsmall_is(n); else if (c == '*') X.mulsmall_is(n); else if (c == '!') { X.become(1); for (int i = 1; i <= n; i += 1) X.mulsmall_is(i); } else cout << "I don't know how to do that\n"; } } }