百度百科>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
struct wint:vector<int>
wint(int n=0)
push_back(n);
check();
wint& check()//
while(!empty()&&!back())pop_back();
if(empty())return *this;
for(int i=1; i<size(); ++i)
(*this)[i]+=(*this)[i-1]/10;
(*this)[i-1]%=10;
while(back()>=10)
push_back(back()/10);
(*this)[size()-2]%=10;
return *this;//
;
istream& operator>>(istream &is,wint &n)
string s;
is>>s;
n.clear();
for(int i=s.size()-1; i>=0; --i)n.push_back(s[i]-\'0\');
return is;
ostream& operator<<(ostream &os,const wint &n)
if(n.empty())os<<0;
for(int i=n.size()-1; i>=0; --i)os<<n[i];
return os;
//常量引用当参数,避免拷贝更高效
bool operator!=(const wint &a,const wint &b)
if(a.size()!=b.size())return 1;
for(int i=a.size()-1; i>=0; --i)
if(a[i]!=b[i])return 1;
return 0;
bool operator==(const wint &a,const wint &b)
return !(a!=b);
bool operator<(const wint &a,const wint &b)
if(a.size()!=b.size())return a.size()<b.size();
for(int i=a.size()-1; i>=0; --i)
if(a[i]!=b[i])return a[i]<b[i];
return 0;
bool operator>(const wint &a,const wint &b)
return b<a;
bool operator<=(const wint &a,const wint &b)
return !(a>b);
bool operator>=(const wint &a,const wint &b)
return !(a<b);
wint& operator+=(wint &a,const wint &b)
if(a.size()<b.size())a.resize(b.size());
for(int i=0; i!=b.size(); ++i)a[i]+=b[i];
return a.check();
wint operator+(wint a,const wint &b)
return a+=b;
wint& operator-=(wint &a,wint b)
if(a<b)swap(a,b);
for(int i=0; i!=b.size(); a[i]-=b[i],++i)
if(a[i]<b[i])//需要借位
int j=i+1;
while(!a[j])++j;
while(j>i)
--a[j];
a[--j]+=10;
return a.check();
wint operator-(wint a,const wint &b)
return a-=b;
wint operator*(const wint &a,const wint &b)
wint n;
n.assign(a.size()+b.size()-1,0);
for(int i=0; i!=a.size(); ++i)
for(int j=0; j!=b.size(); ++j)
n[i+j]+=a[i]*b[j];
return n.check();
wint& operator*=(wint &a,const wint &b)
return a=a*b;
wint divmod(wint &a,const wint &b)
wint ans;
for(int t=a.size()-b.size(); a>=b; --t)
wint d;
d.assign(t+1,0);
d.back()=1;
wint c=b*d;
while(a>=c)
a-=c;
ans+=d;
return ans;
wint operator/(wint a,const wint &b)
return divmod(a,b);
wint& operator/=(wint &a,const wint &b)
return a=a/b;
wint& operator%=(wint &a,const wint &b)
divmod(a,b);
return a;
wint operator%(wint a,const wint &b)
return a%=b;
wint pow(const wint &n,const wint &k)
if(k.empty())return 1;
if(k==2)return n*n;
if(k.front()%2)return n*pow(n,k-1);
return pow(pow(n,k/2),2);
int main()
wint a,b;
cin>>a>>b;
cout<<(a<b)<<endl
<<(a==b)<<endl
<<a+b<<endl
<<a-b<<endl
<<a*b<<endl
<<a/b<<endl
<<a%b<<endl
<<pow(a,b);
高精板子
多次翻车的板子,还在建设中,备注很多是翻车的点......
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
char a1[10002],b1[10002];
int a[10002],b[10002],c[100002],lena,lenb,lenc,i,j,x; //x存进位
void add(){
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
lena=strlen(a1);
lenb=strlen(b1);
for(i=0;i<=lena-1;++i)a[lena-i]=a1[i]-‘0‘;
for(i=0;i<=lenb-1;++i)b[lenb-i]=b1[i]-‘0‘;
lenc=1;
x=0;
while(lenc<=lena||lenc<=lenb){
c[lenc]=a[lenc]+b[lenc]+x;
x=c[lenc]/10;
c[lenc]%=10;
lenc++;
}
c[lenc]=x;
if(c[lenc]==0)lenc--; //最高位进位问题;
for(i=lenc;i>=1;--i)printf("%d",c[i]);
cout<<endl;
}
void subtract(){
char n[10002],n1[10002],n2[10002];
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
memset(n,0,sizeof(n));
memset(n1,0,sizeof(n1));
memset(n2,0,sizeof(n2));
strcpy(n1,a1);
strcpy(n2,b1);
if(strlen(n1)<strlen(n2)||(strlen(n1)==strlen(n2)&&strcmp(n1,n2)<0)){
strcpy(n,n1);
strcpy(n1,n2);
strcpy(n2,n);
printf("-");
}
lena=strlen(n1);
lenb=strlen(n2);
for(i=0;i<=lena-1;++i)a[lena-i]=n1[i]-‘0‘;
for(i=0;i<=lenb-1;++i)b[lenb-i]=n2[i]-‘0‘;
i=1;
while(i<=lena||i<=lenb){
if(a[i]<b[i]){
a[i]+=10;
a[i+1]--;
}
c[i]=a[i]-b[i];
i++;
}
lenc=i-1;//一定记得位数减去最后自增的1;
while((c[lenc]==0)&&(lenc>1)) lenc--;//去掉前导0;
for(i=lenc;i>=1;--i)printf("%d",c[i]);
cout<<endl;
}
void multiply(){
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
lena=strlen(a1);
lenb=strlen(b1);
for(i=0;i<=lena-1;++i)a[lena-i]=a1[i]-‘0‘;
for(i=0;i<=lenb-1;++i)b[lenb-i]=b1[i]-‘0‘;
for(i=1;i<=lena;++i){
x=0;
for(j=1;j<=lenb;++j){//对乘数的每一位进行处理
c[i+j-1]=a[i]*b[j]+x+c[i+j-1];//当前乘积+上次乘积进位+原数
x=c[i+j-1]/10;
c[i+j-1]%=10;
}
c[i+lenb]=x;//进位
}
lenc=lena+lenb;
while((c[lenc]==0)&&(lenc>1)) lenc--;//去掉前导0;
for(i=lenc;i>=1;--i)printf("%d",c[i]);
cout<<endl;
}
void divide(){
}
void mod(){
}
int main(){
// freopen("gj.in","r",stdin);
// freopen("gj.out","w",stdout);
scanf("%s",a1);
scanf("%s",b1);
add();
subtract();
multiply();
// fclose(stdin);
// fclose(stdout);
return 0;
}