hkr1469 @ 2022-08-23 17:30:30
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define SIZE 210
int main() {
char sa[SIZE],sb[SIZE];
cin>>sa>>sb;
int la,lb,lc;
la=strlen(sa);
lb=strlen(sb);
int a[SIZE],b[SIZE],c[2*SIZE];
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
for(int i=la-1; i>=0; i--) { //字符串sa倒序存入数组a
a[i]=sa[la-1-i]-'0';
}
for(int i=lb-1; i>=0; i--) { //字符串sb倒序存入数组b
b[i]=sb[lb-1-i]-'0';
}
int tmp;//乘积
for(int i=0; i<la; i++) {
for(int j=0; j<lb; j++) {
tmp=a[i]*b[j]+c[i+j]; //计算结果存入c
c[i+j+1]+=(tmp/10);//进位
c[i+j]=tmp%10;
}
}
lc=la+lb;
while(c[lc-1]==0&&lc>1) { //处理先导 0
lc--;
}
for(int i=lc-1; i>=0; i--) { //倒序输出c
cout<<c[i];
}
cout<<endl;
return 0;
}
by liangbowen @ 2022-08-23 17:39:42
@hkr1469
by hkr1469 @ 2022-08-23 17:44:52
谢谢 (原来少了个0)