为什么第一个不能过 急急急

P1303 A*B Problem

telankesi @ 2022-11-26 19:59:35


#include <stdio.h>
#include <string.h>
int x[100000];
int y[100000];
int c[100000];
char a[100000];
char b[100000];
int main() {

    scanf("%s", &a);
    scanf("%s", &b);
    int n=strlen(a);
    int m=strlen(b);
    for (int i = 0; i < n; i++) {
        x[i] = a[n - 1 - i] - '0';
    }
    for (int i = 0; i < m; i++) {
        y[i] = b[m - 1 - i] - '0';
    }
    int max = n+m -1;

    for (int i = 0; i < n; i++) {

        for (int j = 0; j < m; j++)
        {
            c[i + j] = c[i + j] + y[j] * x[i];
            if (c[i + j] >= 10) {
                int t = c[i + j];
                c[i + j] %= 10;
                c[i + j + 1] += t / 10;
                if (c[i + j] == max - 1)max++;
            }
            }

    }
    for (int i = 0; i < max; i++) {
        printf("%d", c[max - 1 - i]);
    }

    return 0;
}

by sxshm @ 2023-08-30 10:22:48

@telankesi 特判结果0的情况


|