一个封装了 + , − , × , ÷ +,-,\times,\div +,−,×,÷的高精度结构体
struct BigSum{
int a[MAXN];//已经倒序
int len;
};
void print(BigSum a){
for(int i=a.len;i>=1;i--){
printf("%d",a.a[i]);
}
}
BigSum operator + (BigSum a,BigSum b){
BigSum c;
c.len=1;
int x=0;
int lena=a.len,lenb=b.len;
while(c.len<=lena || c.len<=lenb){
c.a[c.len]=a.a[c.len]+b.a[c.len]+x;
x=c.a[c.len]/10;
c.a[c.len]%=10;
c.len++;
}
c.a[c.len]=x;
while(c.a[c.len]==0 && c.len>1){
c.len--;
}
return c;
}
BigSum operator * (BigSum a,BigSum b){
BigSum c;
int lena=a.len,lenb=b.len;
memset(c.a,0,sizeof(c.a));
for(int i=1;i<=lena;i++){
int x=0;
for(int j=1;j<=lenb;j++){
c.a[i+j-1]=a.a[i]*b.a[j]+x+c.a[i+j-1];
x=c.a[i+j-1]/10;
c.a[i+j-1]%=10;
}
c.a[i+lenb]=x;
}
c.len=lena+lenb;
while(c.a[c.len]==0 && c.len>1){
c.len--;
}
return c;
}