救命!!!

P1303 A*B Problem

Crazy_13754 @ 2021-10-21 10:37:35

莫名奇妙的只能对第一个点

#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>

using namespace std;

    const int MAXN = 1e8;
    int num1[MAXN], num2[MAXN], ans[MAXN];
    char inl1[MAXN], inl2[MAXN];

int main()
{
    ios::sync_with_stdio(0);

    cin >> inl1 >> inl2;
    int len1 = strlen(inl1);
    int len2 = strlen(inl2);

    for(int i = 1; i <= len1; i++)
        num1[i] = inl1[len1-i] - '0';
    for(int i = 1; i <= len2; i++)
        num2[i] = inl2[len2-i] - '0';

    for(int i = 1; i <= len2; i++)
        for(int j = 1; j <= len1; j++)
            ans[j+i-1] += num1[j] * num2[i];

    for(int i = 1; i < len1 + len2; i++)
        if(ans[i] > 9){ 
        ans[i+1] += ans[i]/10;
        ans[i] %= 10;
        }

    int n = len1 + len2;

    while(ans[n] == 0 && n > 1) n--;

    for(int i = n; i >= 1; i--)
        cout << ans[n];
    return 0;
}

by 呙余博的爸爸 @ 2021-11-06 17:31:27

222


|