求调

P1303 A*B Problem

wisdom2010 @ 2024-09-01 12:49:57

最后一个点过不了了,麻烦帮忙看一看,栓q~

#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 10;
int a[maxn], b[maxn], c[maxn] = {0};
string s1, s2;
int main()
{
    ios :: sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> s1 >> s2;
    int len1, len2, len3;
    len1 = s1.size();
    for(int i = 1; i <= len1; i++)
        a[i] = s1[len1 - i] - '0';

    len2 = s2.size();
    for(int i = 1; i <= len2; i++)
        b[i] = s2[len2 - i] - '0';
    if(len1 == 1 && s1[0] == '0')
    {
        cout << "0";
        return 0;
    }
    if(len2 == 1 && s2[0] == '0')
    {
        cout << "0";
        return 0;
    }
    len3 = len1 + len2;
    for(int i = 1; i <= len1; i++)
        for(int j = 1; j <= len2; j++)
            c[i + j - 1] += a[i] * b[j];
    for(int i = 1; i <= len3; i++)
        if(c[i] >= 10)
        {
            c[i + 1] += c[i] / 10;
            c[i] %= 10;
        }
    while(len3 > 0 and c[len3] == 0)
        len3--;
    for(int i = len3; i > 0; i--)
        cout << c[i];
    return 0;
}

by littlep001 @ 2024-09-01 13:11:49

10^{2000} \times 10^{2000} = 10^{4000}

by Xuancheng_Mao @ 2024-09-01 13:18:27

数组开小了,开大一点即可


by King_and_Grey @ 2024-09-01 13:20:39

const int maxn = 4e4 + 10;

@wisdom2010


by wisdom2010 @ 2024-09-01 13:55:22

@littlep001 @Xuancheng_Mao @King_and_Grey 哦哦哦,冒傻气了...谢谢提醒,感谢帮忙!!!


|