[手动滑稽]第五点WA的看过来?

P1303 A*B Problem

HeTaiyu @ 2019-08-28 14:50:32

最后一个点数据超出了题目中所给出的数据范围

下方代码之前数字数组大小maxn设为2019最后一个点WA掉,改为10000就全AC,是题目数据范围给错了?

#include<bits/stdc++.h>
using namespace std;
#define maxn 10000
char a[maxn],b[maxn],ans[maxn];
typedef short sht;
sht alen,blen,anslen;
const char DEC = 10;
void low_high(char* str, sht& len){
    sht half = len/2;
    for(sht i=0; i<half; i++){
        swap(str[i],str[len-i-1]);
        str[i] -= '0', str[len-i-1] -= '0';
    }
    if(len%2!=0) str[half] -= '0';
}

#define MAX(a,b) a>b?a:b;
void mul(const char* a, const char* b, sht& alen, sht& blen, char* ans, sht& anslen){
    for(sht i=0;i<blen;i++)
        for(sht j=0;j<alen;j++){
            //printf("%d(%d)* %d(%d), ",i,a[j],j,b[i]);
            ans[j+i] += a[j]*b[i];
            anslen = MAX(anslen, j+i)
            if(ans[j+i]>=10){
                anslen = MAX(anslen, j+i+1)
                ans[j+1+i] += ans[j+i] / DEC;
                ans[j+i] %= DEC;
            }
        }

    //printf("anslen:%d\n",anslen);
    //printf("\n");
}

int main(){
    char fh = 0;
    cin>>a>>b;
    alen = strlen(a);
    blen = strlen(b);
    //printf("<%d>",alen);
    if(a[0]=='-'){
        fh = !fh;
        for(int i=1;i<alen;i++){
            a[i-1] = a[i];
            a[i] = 0;

        }
        alen--;
    }
    if(b[0]=='-'){
        fh = !fh;
        for(int i=1;i<blen;i++){
            b[i-1] = b[i];
            b[i] = 0;
        }
        blen--;
    }

    low_high(a,alen);
    low_high(b,blen);

    /*printf("a:\n");
    for(sht i = alen - 1; i>=0; i-- )
        printf("%d ",a[i]);
    printf("\n");

    printf("b:\n");
    for(sht i = blen - 1; i>=0; i-- )
        printf("%d ",b[i]);
    printf("\n");

    return 0;*/

    if(alen>=blen) mul(a,b,alen,blen,ans,anslen);
    else mul(b,a,blen,alen,ans,anslen);
    bool zero = false, fhsc = true;
    for(sht i=anslen; i>=0; i--){
        if(ans[i]!=0) zero = true;
        if(fhsc && fh && zero) printf("-"),fhsc = false;
        if(zero) printf("%d",ans[i]);   
    }
    if( zero<=0&&ans[0]==0 ) printf("0");   
    return 0;
}

是题目数据范围给错了。 两个2000位的数字相乘,结果可能会只有2000位

第五WA的同学自己把数组改大。


by    吾皇 @ 2019-08-28 14:53:43

不是你没用Python(滑稽


by OvOAuto @ 2019-08-28 15:10:12

print(int(input()) * int(input()))

by Krite @ 2019-08-28 18:49:36

:-)


by Callous_Murder @ 2019-10-06 14:10:01

@HeTaiyu 神奇,我还真是这样【数组再开小我就女装】


by Genshineer @ 2019-10-07 13:00:51

呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃


by FBBBOOS @ 2021-01-05 18:33:54

em···


|