版本比较
高精度结构体
正文
增加 29 行删除 18 行
12344567789101112121314151620 行未改动373839404141424344454647484950515253525455565758596061626362646566676814 行未改动8384858685878889909126 行未改动11811912012112012212312412512647 行未改动174175176177176178179180181182181183184185186187186188189190191192191193194195196195196197198199200201202201203204205206207206208209210211212211213214215216217218219220221222223224225226227216```cpp#define ll long longstruct BigInt{
ll value[12501]; int p;
BigInt(){ p=1; for(int i=1;i<12501;++i) value[i]=0; }
void GiveValue(string s){ reverse(s.begin(),s.end()); int len=s.size(); p=0;20 行未改动 cin>>s; GiveValue(s); }
void Print(){ void Print(string s){ if(value[1]==0&&p==1){ cout<<"0"; cout<<s; return; } if(value[0]==1) cout<<'-'; for(int i=p;i>=1;--i){ if(i!=p&&value[i]<10000000) cout<<setfill('0')<<setw(8); cout<<value[i]; } cout<<s; }
int CompareWith(BigInt b){ if(value[0]!=b.value[0]) return value[0]?0:2; if(p!=b.p) return p>b.p?2:0; for(int i=p;i>=1;--i) { if(value[i]>b.value[i]) return 2; if(value[i]<b.value[i]) return 0; } return 1; }
int CompareWith(ll b){ BigInt tmp; tmp.GiveValue(b); return CompareWith(tmp);14 行未改动 } if(carry) value[++max_p]=carry; p=max_p; }
void Add(ll b){ BigInt tmp; tmp.GiveValue(b); Add(tmp);26 行未改动 BigInt tmp; tmp.GiveValue(b); Subtract(tmp); }
void Multiply(BigInt b){ BigInt res; res.p=p+b.p; for(int i=1;i<=p;++i){47 行未改动 Divide(tmp); }};
BigInt Add(BigInt a,BigInt b){BigInt operator +(BigInt a,BigInt b){ a.Add(b); return a;}
BigInt Add(BigInt a,ll b){BigInt operator +(BigInt a,ll b){ a.Add(b); return a;}
BigInt Subtract(BigInt a,BigInt b){BigInt operator -(BigInt a,BigInt b){ a.Subtract(b); return a;}
BigInt Subtract(BigInt a,ll b){BigInt operator -(BigInt a,ll b){ a.Subtract(b); return a;} BigInt Multiply(BigInt a,BigInt b){
BigInt operator *(BigInt a,BigInt b){ a.Multiply(b); return a;}
BigInt Multiply(BigInt a,ll b){BigInt operator *(BigInt a,ll b){ a.Multiply(b); return a;}
BigInt Divide(BigInt a,BigInt b){BigInt operator /(BigInt a,BigInt b){ a.Divide(b); return a;}
BigInt Divide(BigInt a,ll b){BigInt operator /(BigInt a,ll b){ a.Divide(b); return a;}
BigInt operator %(BigInt a,BigInt b){ BigInt c=a/b; return a-b*c;}
BigInt operator %(BigInt a,ll b){ BigInt c=a/b; return a-c*b;}```~妈妈再也不用担心孩子不会高精度了!~