高精板子完整版
7.29 Update
支持大小比较,大改码风。
除了负数除法取模位运算
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
class big
{
public:
int a[10001] = {0};unsigned int l = 0;
int & operator[](unsigned int n) {return a[n];}big() {}
big(unsigned long long n) {if(!n) {l = 1;return;}
while(n) a[l++] = n % 10, n /= 10;}
void flt(unsigned int p)
{
l = p;for(int i(0);i < l;++i)
a[i + 1] += a[i] / 10, a[i] %= 10;
while(!a[l] && l) --l;++l;
}
};
istream & operator>>(istream &in, big &n)
{
string t;in >> t;
for(auto i(t.rbegin());i < t.rend();++i) n[n.l++] = *i - '0';
return in;
}
ostream & operator<<(ostream &out, big n)
{for(int i(n.l - 1);i >= 0;--i) out << n[i];return out;}
template<class A, class B> bool operator==(A x, B y)
{big a(x), b(y);return a.l != b.l ? 0 : equal(a.a, a.a + a.l, b.a);}
template<class A, class B> bool operator!=(A x, B y) {return !(x == y);}
template<class A, class B> bool operator<(A x, B y)
{
big a(x), b(y);return a.l != b.l ? a.l < b.l :
lexicographical_compare(a.a, a.a + a.l, b.a, b.a + b.l);
}
template<class A, class B> bool operator<=(A x, B y) {return x < y || x == y;}
template<class A, class B> bool operator>(A x, B y) {return !(x <= y);}
template<class A, class B> bool operator>=(A x, B y) {return !(x < y);}
big operator+(big a, big b)
{
big c;int l(max(a.l, b.l));c.l = l;
for(int i(0);i < l;++i) c[i] = a[i] + b[i];
c.flt(l + 1);return c;
}
big operator-(big a, big b)
{
big c;int l(max(a.l, b.l));c.l = l;for(int i(0);i < l;++i)
{if(a[i] - b[i] < 0) a[i] += 10, --a[i + 1];c[i] = a[i] - b[i];}
c.flt(l);return c;
}
big operator*(big a, big b)
{
big c;int l(a.l + b.l);c.l = l;
for(int i(0);i < a.l;++i) for(int j(0);j < b.l;++j) c[i + j] += a[i] * b[j];
c.flt(l);return c;
}
big & operator+=(big &a, big b) {a = a + b;return a;}
big & operator-=(big &a, big b) {a = a - b;return a;}
big & operator*=(big &a, long long b) {a = a * b;return a;}
big & operator*=(big &a, big b) {a = a * b;return a;}
big & operator++(big &n) {n += 1;return n;}
big operator--(big &n) {n -= 1;return n;}
big operator++(big &n, int) {n += 1;return n - 1;}
big operator--(big &n, int) {n -= 1;return n + 1;}
也 就 不 到 7 0 行