求助!!例子过了,为啥全部WA

P1591 阶乘数码

dongtian @ 2023-03-07 22:27:25

#include<stdio.h>
int a[100][1000],b[3000][3000],c[2000][3000];
int main()
{
    int n,i,j,k=0,l,m;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    scanf("%d%d",&a[i][0],&a[i][1]);
    for(i=0;i<n;i++){
        b[i][0]=1;k=0;
        m=0;
        c[i][k]=1;
        for(j=2;j<=a[i][0];j++)
        {
            c[i][k]*=j;
            if(c[i][k]>9)
            {
                c[i][k+1]=c[i][k]/10;
                k++;
            }
            for(l=0;l<=k;l++)
            {
                b[i][l]*=j;
            }
            for(l=0;l<=k;l++)
            {
                if(b[i][l]>9)
                {
                    b[i][l+1]+=b[i][l]/10;
                    b[i][l]%=10;
                }

            }
        }
        for(l=0;l<=k;l++)
        {
            if(b[i][l]==a[i][1])
                m++;
        }
        printf("%d\n",m);
    }
    return 0;
}

by xujiaxiang @ 2023-03-09 23:21:41

#include<bits/stdc++.h> 
using namespace std;
int a[11][2],b[11][3000],c[11];
int main()
{
    int t,i,j,k,l,m;
    scanf("%d",&t); //组数 t
    for(i=1;i<=t;i++){
        scanf("%d%d",&a[i][0],&a[i][1]);  //0存n,1存a 
    }
    memset(b,0,sizeof(b));
    for(i=1;i<=t;i++)//循环t组 
    {
        b[i][0]=1;//第i组个位初始化1 
        c[i]=1;//位数1位 
        for(j=2;j<=a[i][0];j++) //每组从2乘到n 
        {

            for(k=0;k<c[i];k++)//每一位乘j,个位0,最高位c[i]-1 
            {
                b[i][k]*=j;
                //cout<<"multiply  "<<"i: "<<i<<" k: "<<k<<" "<<b[i][k]<<endl; 
            }
            for(l=0;l<c[i];l++)//每一位开始向上一位进位 
            {
                b[i][l+1]+=b[i][l]/10;//进位 
                b[i][l]%=10;//余数 
                //cout<<"carry  "<<"i: "<<i<<" l:   "<<l<<" "<<b[i][l]<<endl; 

            }
            //cout<<"last:  "<<"i: "<<i<<" c[i]: "<<c[i]<<" "<<b[i][c[i]]<<endl;
            if(b[i][c[i]]>0)
            {
                if(b[i][c[i]]<10)
                {
                    c[i]+=1;
                    //cout<<"c[i]: "<<c[i]<<endl;
                }   
                else
                {
                    c[i]+=1;
                    while(b[i][c[i]-1]>9)//处理最高位进位 
                    {
                        //cout<<"处理最高位进位"<<endl;
                        b[i][c[i]]+=b[i][c[i]-1]/10;//进位
                        b[i][c[i]-1]%=10;//余数 
                        c[i]+=1;
                        //cout<<"carry  "<<"i: "<<i<<" c[i]-1:   "<<c[i]-1<<" "<<b[i][c[i]-1]<<endl; 
                        //cout<<"carry  "<<"i: "<<i<<" c[i]:     "<<c[i]<<" "<<b[i][c[i]]<<endl;
                        //cout<<"c[i]: "<<c[i]<<endl;   
                    }
                }

            } 

        }
        m=0;
        for(l=c[i]-1;l>=0;l--)
        {
            //cout<<b[i][l];
            if(b[i][l]==a[i][1])   m++;
        }
        printf("%d\n",m);
    }
    return 0;
}

by xujiaxiang @ 2023-03-09 23:22:25

做了点改编 希望对你有帮助(


|