60分,最后3个点RE。

P1303 A*B Problem

abelzhaoqin @ 2023-01-28 21:06:07

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

int main()
{
    char a_str[201] = {},b_str[201] = {};
    int a_int[201] = {},b_int[201] = {};
    int len_a = 0,len_b = 0;
    int ans[420] = {};
    int len_ans = 0;
    cin >> a_str >>b_str;
    len_a = strlen(a_str);
    len_b = strlen(b_str);
    for (int i = 0; i < len_a; i++)
    {
        a_int[i] = a_str[len_a - 1 - i] - '0';
    }
    for (int i = 0; i < len_b; i++)
    {
        b_int[i] = b_str[len_b - 1 - i] - '0';
    }
    int in=0;
    for (int j = 0; j < len_b; j++)
    {
        for (int i = 0; i < len_a; i++)
        {
            ans[i + j] = a_int[i] * b_int[j] + in + ans[i + j];
            in = ans[i + j] / 10;
            ans[i + j] %= 10;
        }
        ans[len_a + j] += in;
        in = 0;
    }
    len_ans=len_b+len_a;
    while (ans[len_ans - 1] == 0 && len_ans > 1)
    {
        len_ans--;
    }
    for(int i=len_ans-1;i>=0;i--)
    {
        if(ans[len_ans - 1] == 0 && len_ans > 1)
        {
            len_ans--;
        }
        cout <<ans[i];
    }
    return 0;
}

by q2q2 @ 2023-02-02 14:09:04

数组开小了


by abelzhaoqin @ 2023-03-04 10:18:29

@q2q2 谢谢


|