#include <iostream>
#include <cmath>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
string A, B;
cin >> A >> B;
if (A == "0" || B == "0") {
cout << 0 << endl;
return 0;
}
int len_A = A.size(), len_B = B.size();
int len_res = len_A + len_B;
int a[len_A], b[len_B], res[len_res];
memset(res, 0, sizeof(res));
for (int i = len_A - 1, j = 0; i >= 0; i--, j++) {
a[j] = A[i] - '0';
}
for (int i = len_B - 1, j = 0; i >= 0; i--, j++) {
b[j] = B[i] - '0';
}
for (int i = 0; i < len_B; i++) {
for (int j = 0; j < len_A; j++) {
res[i + j] += b[i] * a[j];
}
}
for (int i = 0; i < len_res - 1; i++) {
res[i + 1] += res[i] / 10;
res[i] %= 10;
}
if (!res[len_res - 1]) {
len_res--;
}
for (int i = len_res - 1; res[i] == 0; i--) {
len_res--;
}
for (int i = len_res - 1; i >= 0; i--) {
cout << res[i];
}
cout << endl;
return 0;
}
来源:CSDN
作者:天亮就睡觉
链接:https://blog.csdn.net/weixin_43971049/article/details/104005324