求助,为啥RE了...

P1303 A*B Problem

Brunhild @ 2020-07-20 18:01:09

RT

#include <bits/stdc++.h>
using namespace std;
struct BigInt
{
    static const int M = 1000;
    int num[M + 10], len;
    BigInt() { clean(); }    
    void clean(){
        memset(num, 0, sizeof(num));
        len = 1;
    }
    void read(){
        char str[M + 10];
        scanf("%s", str); 
        len = strlen(str);
        for(int i = 1; i <= len; i++)
            num[i] = str[len - i] - '0';
    }
    void write(){
        for(int i = len; i >= 1; i--)
            printf("%d", num[i]);
    }
    BigInt operator * (const BigInt &A) const{
        BigInt S;
        if (num[1]==0||A.num[1]==0) return S;
           S.len=len+A.len;
           for (int i=1;i<=A.len;i++){
               for (int j=1;j<=len;j++){
                S.num[i+j-1]+=num[j]*A.num[i];
               }
           }
           for (int i=1;i<=S.len;i++){
            if (S.num[i]>=10){
                    S.num[i+1]+=S.num[i]/10;
                    S.num[i]%=10;
                }
           }
           if (!S.num[S.len]) S.len--;
           return S;
    }
};
int main()
{
    BigInt x,y,ans;
    x.read();
    y.read();
    ans=x*y;
    ans.write();
}

前面几个点都过了,就最后一个点RE了...


by Rubyonly @ 2020-07-20 18:03:26

M=1000就可以了


by Rubyonly @ 2020-07-20 18:03:59

一般RE基本上是数组太小的问题,开大点就好了


by Rubyonly @ 2020-07-20 18:07:21

@Brunhild


by Smile_Cindy @ 2020-07-20 18:23:45

@Brunhild

M=2000


by Brunhild @ 2020-07-20 19:43:23

谢谢~


by Brunhild @ 2020-07-20 20:35:43

此贴完结


|