#include<iostream>
#include<cstring>
using namespace std;
void multiply(const char* a, const char* b){
int aLen = strlen(a);
int bLen = strlen(b);
int *result = new int[aLen+bLen];
for(int i=0; i<(aLen+bLen); i++)
result[i]=0;
for(int i=0; i<aLen; i++)
for(int j=0;j<bLen; j++){
result[i+j+1]+=(a[i]-'0')*(b[j]-'0');
}
for(int i=(aLen+bLen-1); i>=0; i--){
if(result[i]>=10){
result[i-1]+=result[i]/10;
result[i]%=10;
}
}
int i=0;
while(result[i]==0) i++;
for(int j=i; j<(aLen+bLen); j++)
cout<<result[j];
cout<<endl;
}
int main(){
string a,b;
cin>>a>>b;
const char *num1=a.c_str();
const char *num2=b.c_str();
multiply(num1,num2);
return 0;
}
大数相乘
最新推荐文章于 2024-01-20 09:00:00 发布