#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] == 0) {
len_res--;
}
for (int i = len_res - 1; i >= 0; i--) {
cout << res[i];
}
cout << endl;
return 0;
}
高精度乘法
最新推荐文章于 2022-10-09 22:37:34 发布