题解
2024-06-14 13:05:06
发布于:广东
29阅读
0回复
0点赞
#include <iostream>
#include <cstring>
using namespace std;
char a[2005], b[2005];
short a1[10005], b1[10005], c[10005];
int x;
int main(){
cin >> a >> b;
int lena = strlen(a), lenb = strlen(b);
for(int i = 0; i < lena; i++){//倒序
a1[lena - i] = a[i] - '0';
}for(int i = 0; i < lenb; i++){
b1[lenb - i] = b[i] - '0';
}
for(int i = 1; i <= lena; i++){//乘法
int x = 0;
for(int j = 1; j <= lenb; j++){
c[i + j - 1] = x + a1[i] * b1[j] + c[i + j - 1];
x = c[i + j - 1] / 10;
c[i + j - 1] %= 10;
}
c[i + lenb] = x;
}
int maxn = lena + lenb;
while(c[maxn] == 0 && maxn > 1) maxn--;
for(int i = maxn; i > 0; i--) cout << c[i];
}
这里空空如也
有帮助,赞一个