#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
using namespace std;
const int N=5e5+10;
int A[N],B[N],C[N];
int mul(int sizeA,int sizeB)
{
for(int i=1;i<=sizeA;i++)
for(int j=1;j<=sizeB;j++)
{
C[i+j-1]+=A[i]*B[j];
}
int len=sizeA+sizeB;
for(int i=1;i<len;i++)
{
if(C[i]>9) C[i+1]+=C[i]/10; C[i]%=10;//进位
}
while(C[len]==0&&len>1) len--;//去高位0
return len;
}
int main()
{
string a,b;
cin>>a>>b;
for(int i=1;i<=a.size();i++) A[i]=a[a.size()-i]-'0';
for(int i=1;i<=b.size();i++) B[i]=b[b.size()-i]-'0';
int len=mul(a.size(),b.size());
for(int i=len;i>=1;i--)
cout<<C[i];
return 0;
}
来源:CSDN
作者:晓屈
链接:https://blog.csdn.net/weixin_44488944/article/details/103949208