80分求救

P1303 A*B Problem

Sprunki_Rabbit @ 2024-07-27 14:10:37

#include <iostream>
#include <cstring>
using namespace std;

int main()
{
    char a2[1001],b2[1001];
    int a[1001],b[1001],s,ss,s3,x,c[10001];
    cin >> a2;
    cin >> b2;
    s = strlen(a2);
    ss = strlen(b2);

    for(int i=0;i<=s-1;i++)
        a[s-i] = a2[i] - '0';
    for(int i=0;i<=ss-1;i++)
        b[ss-i] = b2[i] - '0';
    for(int i=1;i<=s;i++)
    {
        x = 0;
        for(int j=1;j<=ss;j++)
        {
            c[i+j-1] = a[i] * b[j]+x+c[i+j-1];
            x = c[i+j-1]/10;
            c[i+j-1] %= 10;
        }
        c[i+ss] = x;
    }
    s3 = s+ss;
    while(c[s3] == 0 && s3 > 1)
        s3--;
    for(int i=s3;i>=1;i--)
        cout << c[i];

    return 0;
}

by littleFond @ 2024-08-04 17:02:18

你这输入有一个是0就会输出max(s,ss)个0,应该加一个特判0


by Sprunki_Rabbit @ 2024-08-12 14:23:54

@littleFond 好的谢谢


by littleFond @ 2024-08-14 15:12:03

求关注^_^


|