求助大佬们,样例过得去但全WA,不知道问题出在哪里

P1591 阶乘数码

Wotoosh @ 2021-11-10 14:12:54

#include<iostream>
#include<cstring>
using namespace std;
int multiply(int num,int a)
{
    int s1[5000]={1,-1};
     int k,i,j,sum=0;
     for(j=2;j<=num;j++)
    {
    for(k=0;s1[k]!=-1;k++)
    {
        s1[k]*=j;
    }
    s1[k]=0;
    k=k+3;
    for(i=0;i<k;i++)
    {
        s1[i+1]+=s1[i]/10;
        s1[i]%=10;
    }
    while(s1[k]==0)
    k--;
    s1[k+1]=-1;
    }
    i=0;
   while(s1[i]!=-1)   
    {
    if(s1[i]==a)
    sum++;
    i++;
    }
    return sum;
}
int main()
{
    int n,num,a,sum,i;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>num>>a;
        sum=multiply(num,a);
        cout<<sum<<endl;
    }
    return 0;
}

by 31919814111hh @ 2021-11-30 18:48:47

把加位数放进计算里每次计算都要判断加不加位数


|