90分,第一个点wa,咕值掉了下不了点,求助

P1591 阶乘数码

flashfear @ 2024-11-16 16:26:36


#include <iostream>

using namespace std;

int main() {
    // 实现一个高精度阶乘。
    int t, n, a;
    int ans[10010] = {0};

    cin >> t;

    for (int x = 1; x <= t; x++) {
        cin >> n >> a;
        ans[0] = 1;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < 2500; j++)
                ans[j] *= i;

            for (int j = 0; j < 2500; j++)
                if (ans[j] > 9) {
                    ans[j + 1] += ans[j] / 10;
                    ans[j] %= 10;
                }
        }

        int cnt = 2500, cnt2 = 0;
        while (ans[cnt] == 0)
            cnt--;

        for (int i = 0; i <= cnt; i++) {
            if (ans[i] == a) cnt2++;
            ans[i] = 0;
        }

        cout << cnt2 << "\n";
    }

    return 0;
}

by wangshengchen @ 2024-11-16 16:33:05

@flashfear

#include<iostream>
#include<string.h>
using namespace std;

int num[100000];

int main(){
    int n;
    cin>>n;
    while(n--){
        int p,a;
        cin>>p>>a;
        memset(num,0,sizeof(num));
        num[0]=1;
        int len=1;
        for(int i=2; i<=p; i++){
            int carry=0;
            for(int j=0; j<len; j++){
                num[j]*=i;
                num[j]+=carry;
                carry=num[j]/10;
                num[j]%=10;
            }
            while(carry>0){
                num[len]=carry%10;
                len++;
                carry/=10;
            }
        }
        int cnt=0;
        for(int i=0; i<len; i++){
            if(num[i]==a) cnt++;
        }
        cout<<cnt<<"\n";
    }
    return 0;
}

by c22j33c43 @ 2024-11-17 06:36:55

@wangshengchen 你是要指出人家错哪了,又不说错哪了,又不在别人的代码上改,别人怎么搞,他也不好意思再问麻烦你,又去找人了。


|