一直过不了,请问哪里有问题?

P1303 A*B Problem

LABC123456 @ 2024-10-02 13:34:07

#include<iostream>
#include<string>
#define maxn 5010
using namespace std;
int a1[maxn], a2[maxn], a3[maxn];
int main()
{
    string a, b;
    getline(cin, a);
    getline(cin, b);
    if (a == "0" || b == "0")
     {
       cout << 0;
       return 0;
      }
    int lena = a.length(), lenb = b.length();
    for (int i = lena-1; i>=0 ; i--)
        a1[lena - i] = a[i] - '0';
    for (int i = lenb-1; i >=0; i--)
        a2[lenb - i] = b[i] - '0';
    for (int i = 1; i <= lena; i++) {
        for (int j = 1; j <= lenb; j++) {
            a3[i + j-1] += a1[i] * a2[j];
        }
    }
    int len = lena + lenb;
    for (int i = 1; i <= len; i++)
    {
        a3[i + 1] += a3[i] / 10;
        a3[i] %= 10;
    }
    for(;!a3[len];)
        len--;
    for (int i = max(1,len); i >= 1; i--)
        cout << a3[i];
    cout << endl;

    return 0;
1. 1.  }

by dongzirui0817 @ 2024-10-02 13:54:21

@LABC123456 最下面的是啥?


by dongzirui0817 @ 2024-10-02 13:56:57

@LABC123456 估计是这个数据有点问题,建议别用getline


by dongzirui0817 @ 2024-10-02 13:57:19

不一定,没事了


by LABC123456 @ 2024-10-02 19:45:16

@dongzirui0817 请问问题出在哪里了呢?


by dongzirui0817 @ 2024-10-02 21:03:16

@LABC123456 我也不知道啊


|