weimuhan @ 2022-03-23 21:44:55
#include <bits/stdc++.h>
using namespace std;
string num1, num2;
int a1[2200], a2[2200], len1, len2, a[2200], len;
int main() {
cin >> num1 >> num2;
len1 = num1.size();
if (num1 == "0" || num2 == "0") {
cout << 0 ;
return 0;
}
for (int i = 0; i < len1; i++) {
a1[i] = num1[len1 - i - 1] - '0';
}
len2 = num2.size();
for (int i = 0; i < len2; i++) {
a2[i] = num2[len2 - 1 - i] - '0';
}
for (int i = 0; i < len1; i++) {
for (int j = 0; j < len2; j++) {
a[i + j] += a1[i] * a2[j];
}
}
len = len1 + len2 - 1;
for (int i = 0; i < len; i++) {
a[i + 1] += a[i] / 10;
a[i] %= 10;
}
while (a[len]) {
a[len + 1] += a[len] / 10;
a[len] %= 10;
len++;
}
for (int i = len - 1; i >= 0; i--) {
cout << a[i];
}
return 0;
}
by sxshm @ 2023-08-30 10:24:55
@weimuhan 结果数组开成输入数组的两倍