输出全是0 ???
查看原帖
输出全是0 ???
719201
INT_1024楼主2022/11/7 21:24
#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;
}
2022/11/7 21:24
加载中...