大佬看看为啥不能出结果

P1303 A*B Problem

songshihao666888 @ 2023-02-10 16:26:50

#include<iostream>
using namespace std;
int main()
{
    string a, b;
    int res[4001] = { 0 }, n1[2001] = { 0 }, n2[2001] = {0};
    cin >> a >> b;
    for (int i = a.length()-1,j=2000; i>=0; i--,j--)
    {
        n1[j] = a[i]-'0';
    }
    for (int i = b.length() - 1, j = 2000; i >= 0; i--, j--)
    {
        n2[j] = b[i]-'0';
    }
    for (int i = 2000; i>=0 ; i--)
    {
        for (int j = 2000; i>=0; j--)
        {
            res[i + j] += (n1[i] * n2[j]);
            if (res[i + j] >= 10)
            {
                res[i + j - 1] = res[i + j] / 10;
                res[i + j] %= 10;
            }
        }
    }
    int weishu;
    for (int i = 0;; i++)
    {
        if (res[i] != 0)
        {
            weishu = i;
            break;
        }
    }
    if (res[weishu] >= 10)
    {
        res[weishu - 1] = res[weishu] / 10;
        res[weishu] %= 10;
    }
    for (int i = 0;; i++)
    {
        if (res[i] != 0)
        {
            weishu = i;
            break;
        }
    }
    for (int i = weishu; i <= 4000; i++)
    {
        cout << res[i];
    }
    return 0;
}

by Misophiliac @ 2023-02-10 16:31:17

@songshihao666888 双层循环内层条件应该是j>=0


|