2016/11/15
高精度存档
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
inline int max(int a, int b) {
return a > b ? a : b;
}
namespace BigNumbers {
#define positive true
#define negative false
class BigInteger {
bool symbol;
short *store;
int capacity, length;
void push_forward() {
for (int i = 0; i < length;i++)
if (store[i]>9) {
store[i + 1] += store[i] / 10;
store[i] %= 10;
}
if (store[length])length++;
}
void realloc(int size) {
short *temp = new short[size];
memcpy(temp, store, sizeof(short)*capacity);
capacity = size;
delete store;
store = temp;
}
public:
BigInteger() {
symbol = positive;
store = new short[1];
capacity = 1;
length = 1;
store[0] = 0;
}
friend istream &operator >>(istream &in, BigInteger &targ);
friend ostream &operator <<(ostream &out, BigInteger &targ);
friend BigInteger operator +(BigInteger, BigInteger&);
friend BigInteger operator -(BigInteger, BigInteger&);
friend BigInteger operator *(BigInteger, BigInteger&);
};
string __buffer;
istream &operator >>(istream &in, BigInteger &targ) {
cin >> __buffer;
targ.realloc(__buffer.size());
if (__buffer[0] == '-')
targ.symbol = negative, __buffer = __buffer.substr(1);
int curser = 0;
for (int i = __buffer.length() - 1; i >= 0; i--, curser++)
targ.store[curser] = __buffer[i]-'0';
return in;
}
ostream &operator <<(ostream &out, BigInteger &targ) {
if (!targ.symbol)out << '-';
for (int i = targ.length - 1; i >= 0; i--)
out << targ.store[i];
return out;
}
BigInteger operator +(BigInteger a, BigInteger &b) {
int maxlen = max(a.length, b.length);
while (maxlen >= a.length)a.realloc(maxlen);
for (int i = 0; i < maxlen; i++)
a.store[i] += b.store[i];
a.push_forward();
return a;
}
BigInteger operator -(BigInteger a, BigInteger &b) {
return a;
}
BigInteger operator *(BigInteger a, BigInteger &b) {
int maxlen = max(a.length, b.length);
if (maxlen > a.capacity)a.realloc(maxlen);
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < b.length; j++)
a.store[i] *= b.store[j];
}
a.push_forward();
return a;
}
}
int main() {
BigNumbers::BigInteger a, b;
cin >> a >> b;
cout << a*b;
}