A*B 高精度(自取)
2023-08-17 14:22:48
发布于:广东
#include <bits/stdc++.h>
using namespace std;
string a,b;
void remove0(string &s){
while (s[0]=='0' && s.size()>1) s.erase(s.begin());
}
bool al(string a,string b){
if (a.size()!=b.size()) return a.size()<b.size();
return a<b;
}
string mul(string a,string b){
string c(a.size()+b.size(),0);
reverse(a.begin(),a.end());
reverse(b.begin(),b.end());
for (int i=0;i<a.size();i++){
for (int j=0;j<b.size();j++){
int k=i+j;
c[k]+=(a[i]-'0')*(b[j]-'0');
c[k+1]+=c[k]/10;
c[k]%=10;
}
}
reverse(c.begin(),c.end());
for (int i=0;i<c.size();i++){
c[i]+='0';
}
remove0(c);
return c;
}
int main(){
cin >> a >> b;
cout << mul(a,b);
}
这里空空如也
有帮助,赞一个