INT_1024 @ 2022-11-07 21:24:43
#include<iostream>
#include<vector>
using namespace std;
vector<int> num1, num2;
void multiplication(vector<int> ans) {
for (int i = 1; i < num1.size(); i++) {
for (int j = 1; j < num2.size(); j++) {
ans[i + j - 1] += num1[i] * num2[j];
ans[i + j] += ans[i + j - 1] / 10;
ans[i + j - 1] %= 10;
}
}
while (ans.size() >= 1 && ans.back() == 0) ans.pop_back();
}
int main() {
string str1, str2;
cin >> str1 >> str2;
for (int i = str1.size() - 1; i >= 0; i--)
num1.push_back(str1[i] - '0');
for (int i = str2.size() - 1; i >= 0; i--)
num2.push_back(str2[i] - '0');
vector<int> ans(num1.size() + num2.size() + 7, 0);
multiplication(ans);
for (int i = ans.size() - 1; i >= 0; i--)
cout << ans[i];
return 0;
}
by zhizhi_c @ 2022-11-08 15:48:27
@zhouxinhao 去掉clear
by zhizhi_c @ 2022-11-08 17:11:28
@zhouxinhao ans加引用
by INT_1024 @ 2022-11-08 18:16:24
@zhizhi_c OKOK