这个是一个高精度的模板,还在完成中。。。
1 #include<iostream> 2 #include<algorithm> 3 #include<cstdio> 4 #include<cstdlib> 5 #include<cmath> 6 #include<cstring> 7 #include<vector> 8 #define xh(a,b,c)for(int a=(b);a<=(c);a++) 9 #define dxh(a,b,c)for(int a=(b);a>=(c);a--) 10 #define bxh(a,b)for(int a=beg[b];a;a=ne[a]) 11 #define hy(a)memset(a,0,sizeof(a)) 12 #define sqr(a) (a)*(a) 13 #define Max(a,b) a=max(a,b) 14 #define Min(a,b) a=min(a,b) 15 #define ll long long 16 #define lof double 17 #define ch char 18 using namespace std; 19 void qin(int &x){ 20 int base=1,num; 21 ch c=getchar(); 22 while(!(c==‘-‘||c>=‘0‘&&c<=‘9‘||c==EOF))c=getchar(); 23 if(c==EOF)exit(0); 24 if(c==‘-‘)base=-1,c=getchar(); 25 num=c-‘0‘; 26 c=getchar(); 27 while(c>=‘0‘&&c<=‘9‘){ 28 num*=10; 29 num+=c-‘0‘; 30 c=getchar(); 31 } 32 x=num*base; 33 } 34 ch integ[50]; 35 void qout(int x){ 36 if(x<0)putchar(‘-‘),x=-x; 37 int len=0; 38 do{ 39 integ[len++]=x%10+‘0‘; 40 x/=10; 41 }while(x); 42 43 while(len--){ 44 putchar(integ[len]); 45 } 46 } 47 struct bigint{ 48 vector<int> v; 49 bigint(long long a = 0){ 50 *this = a; 51 } 52 bigint operator =(long long a){ 53 v.clear(); 54 while(a){ 55 v.push_back(a%10000); 56 a/=10000; 57 } 58 return *this; 59 } 60 bigint operator =(string a){ 61 v.clear(); 62 int x,len=(a.length()-1)/4+1; 63 xh(i,0,len-1){ 64 int e,s; 65 e=a.length()-i*4; 66 s=max(0,e-4); 67 sscanf(a.substr(s,e-s).c_str(),"%d",&x); 68 v.push_back(x); 69 } 70 return *this; 71 } 72 bigint operator +(bigint &b){ 73 bigint c; 74 c.v.clear(); 75 for(int i=0,g=0;;i++){ 76 if(g==0&&i>=v.size()&&i>=b.v.size())break; 77 int x=g; 78 if(i<v.size())x+=v[i]; 79 if(i<b.v.size())x+=b.v[i]; 80 c.v.push_back(x%10000); 81 g=x/10000; 82 } 83 return c; 84 } 85 bigint operator *(bigint &b){ 86 bigint c; 87 c.v.clear(); 88 c.v.resize(v.size()+b.v.size()); 89 for(int i=0;i<v.size();i++) 90 for(int j=0;j<b.v.size();j++){ 91 c.v[i+j]+=b.v[j]*v[i]; 92 c.v[i+j+1]+=c.v[i+j]/10000; 93 c.v[i+j]%=10000; 94 } 95 if(c.v[c.v.size()-1]==0)c.v.pop_back(); 96 return c; 97 } 98 99 100 }; 101 ostream& operator<< (ostream &out,const bigint &x){ 102 out<<x.v.back(); 103 dxh(i,x.v.size()-2,0){ 104 char s[10]; 105 sprintf(s,"%04d",x.v[i]); 106 xh(j,0,strlen(s)-1)cout<<s[j]; 107 } 108 return out; 109 } 110 istream& operator >>(istream &in,bigint &x){ 111 string s; 112 if(!(in>>s))return in; 113 x=s; 114 } 115 bigint a,b,c; 116 int main(){ 117 cin>>a; 118 cin>>b; 119 c=a*b; 120 cout<<c<<endl; 121 return 0; 122 }
时间: 2024-10-21 11:12:49