[模板]高精度四则运算
struct Number{
int a[N],n;bool POrN;
void init(){
memset(a,0,sizeof(a));
n=1;POrN=true;
}
void read(){
init();--n;
char c=getchar();
while(!isdigit(c)){
if(c=='-') POrN=false;
c=getchar();
}
while(isdigit(c)){
a[n++]=c-'0';c=getchar();
}
}
void write(){
if(!POrN) cout<<"-";
for(int i=0;i (const Number a,const Number b){
return b= (const Number a,const Number b){
return b<=a;
}
void tran(){
for(int i=0;i<(n>>1);++i){
swap(a[i],a[n-i-1]);
}
}
Number add(Number a,Number b){
Number c;c.init();
c.n=max(a.n,b.n);
a.tran();b.tran();
for(int i=0;i=10){
c.a[i]-=10;++c.a[i+1];
}
}
while(c.a[c.n]) ++c.n;
c.tran();
return c;
}
Number sub(Number a,Number b){
Number c;c.init();
c.n=max(a.n,b.n);
a.tran();b.tran();
for(int i=0;i1&&!c.a[c.n-1]) --c.n;
c.tran();
return c;
}
friend Number operator + (Number a,Number b){
Number c;bool fl=false;
if(a.POrN^b.POrN){
if(!a.POrN){
swap(a,b);fl=true;
}
if(a.abs(a)10){
c.a[i+1]+=c.a[i]/10;c.a[i]%=10;
}
while(c.n>1&&!c.a[c.n-1]) --c.n;
a.tran();b.tran();c.tran();
return c;
}
bool cmp(Number c,int s,int t){
if(t-s>n) return true;
if(t-sa[i];
}
return true;
}
void sub(Number b,int s,int t){
for(int i=t-1,j=b.n-1;j>=0;--i,--j){
a[i]-=b.a[j];
if(a[i]<0) a[i]+=10,--a[i-1];
}
return;
}
friend Number operator / (Number a,Number b){
Number c,d=a;c.init();
c.POrN=!(a.POrN^b.POrN);c.n=0;
for(int s=0,t=b.n;t<=d.n;){
while(b.cmp(d,s,t)){
d.sub(b,s,t);++c.a[c.n];
if(!d.a[s]) ++s;
}
++c.n;++t;
if(!d.a[s]) ++s;
}
int cnt=0;
while(cnt
2020-01-01 10:53:51