高精度模板
copy老师的代码
#include<bits/stdc++.h>
using namespace std;
char ch[500000];
struct node{
int s[1000000],len;
void init(){
scanf("%s",ch+1);
len=strlen(ch+1);
for(int i=1;i<=len;++i) s[len-i+1]=ch[i]-48;
}
void multi(){
++len;
for(int i=len;i;--i) s[i]=s[i-1];
}
void divid(){
for(int i=1;i<=len;++i) s[i]=s[i+1];
--len;
}
friend bool operator <= (const node &a,const node &b){
if(a.len^b.len) return a.len<b.len;
for(int i=a.len;i;--i) if(a.s[i]^b.s[i]) return a.s[i]<b.s[i];
return 1;
}
friend void operator -= (node &a,const node &b){
for(int i=1;i<=b.len;++i) a.s[i]-=b.s[i];
for(int i=1;i<=a.len;++i) if(a.s[i]<0) a.s[i]+=10,a.s[i+1]--;
while(a.len!=1&&a.s[a.len]==0) a.len--;
}
friend void operator += (node &a,const node &b){
a.len=max(a.len,b.len)+1;
for(int i=1;i<=a.len;++i) a.s[i]+=b.s[i];
for(int i=1;i<=a.len;++i) if(a.s[i]>9) a.s[i]-=10,a.s[i+1]++;
while(a.len!=1&&a.s[a.len]==0) a.len--;
}
friend void operator *= (node &a,const node &b){
node c;c.len=a.len*b.len+10;
for(int i=1;i<=a.len;++i)
for(int j=1;j<=b.len;++j)
c.s[i+j-1]+=a.s[i]*b.s[j];
for(int i=1;i<=c.len;++i) if(c.s[i]>9) c.s[i+1]+=c.s[i]/10,c.s[i]%=10;
while(c.len!=1&&c.s[c.len]==0) c.len--;
a=c;
}
friend void operator %= (node &a,const node &d){
node b=d;int x=b.len;
while(b<=a) b.multi();b.divid();
node c;c.s[c.len=0]=0;
while(b.len>=x){
++c.len;
while(b<=a) a-=b,++c.s[c.len];
b.divid();
}
c.len=max(c.len,1);//防止a<d的情况出不来数
}
friend void operator /= (node &a,const node &d){
node b=d;int x=b.len;
while(b<=a) b.multi();b.divid();
node c;c.s[c.len=0]=0;
while(b.len>=x){
++c.len;
while(b<=a) a-=b,++c.s[c.len];
b.divid();
}
c.len=max(c.len,1);//防止a<d的情况出不来数
a=c;
}
}n,m;
int main(){
n.init(),m.init();
n/=m;
for(int i=1;i<=n.len;++i)printf("%d",n.s[i]);
}
标签:node,10,ch,高精度,int,len,板子,while
From: https://www.cnblogs.com/gsczl71/p/17854537.html