样例过了,但是全WA

P1591 阶乘数码

laozhang_123 @ 2023-11-03 19:55:53

#include<bits/stdc++.h>
#define maxn 1000
using namespace std;
struct Bigint{
    int len,a[maxn];
    Bigint(int x=0){
        memset(a,0,sizeof(a));
        for(len=1;x;len++)
            a[len]=x%10,x/=10;
        len--;
    }
    int &operator[](int i){
        return a[i];
    }
    int finds(int s){
        int cnt=0;
        for(int i=1;i<=len;i++){
            if(a[i]==s)
                cnt++;}
        return cnt;
    }
    void flatten(int L){
        len=L;
        for(int i=1;i<=len;i++)
            a[i+1]+=a[i]/10,a[i]%=10;
        for(;!a[len];) len--;
    }
    void print(){
        for(int i=max(len,1);i>=1;i--)
            printf("%d",a[i]);
    }
}; 
Bigint operator*(Bigint a,int b){
    Bigint c;
    int len=a.len;
    for(int i=1;i<=len;i++)
        c[i]=a[i]*b;
    c.flatten(len+11);
    return c;
}
int main(){
    int m,a,b;
    cin>>m;
    for(int i=1;i<=m;i++){
        Bigint ans(1);
        cin>>a>>b;
        for(int j=1;j<=a;j++)
            ans=ans*j;
        cout<<ans.finds(b)<<endl;}
    return 0;
} 

by zhiyantao @ 2023-11-16 19:45:19

数组开10000就能过了


|