高精度乘法
一如既往的重载运算符
sto zhx orz
#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;
struct gaojing {
int z[123456];
int l;
gaojing() {
memset(z,0,sizeof(z));
l=1;
}
friend istream& operator>>(istream &cin,gaojing &v) {
static char s[100000];
cin >> s;
int l=strlen(s);
for (int a=0; a<l; a++)
v.z[a] = s[l-a-1] - '0';
v.l=l;
return cin;
}
friend ostream& operator<<(ostream &cout,const gaojing &v) {
for (int a=v.l-1; a>=0; a--)
cout << v.z[a];
return cout;
}
};
gaojing operator*(const gaojing &a,const gaojing &b) {
gaojing c;
int l = a.l+b.l;
for(int i=0; i<a.l; i++)
for(int j=0; j<b.l; j++)
c.z[i+j] += a.z[i] * b.z[j];
for(int i=0; i<l; i++){
c.z[i+1] += c.z[i] /10;
c.z[i] = c.z[i] % 10;
}
while(l>0 && c.z[l]==0) l--;
l++;
c.l=l;
return c;
}
int main() {
gaojing a,b;
cin >> a >> b;
cout << a*b << endl;
}