我到底错哪了,救救孩子吧

P1591 阶乘数码

fussyguy @ 2020-11-02 21:22:35

#include<bits/stdc++.h>
using namespace std;
int t;
int n,a;
int ls=1;
int s[10001];
int times(int s[]){
    int ans=0;
    for(int i=1 ; i<=ls ; i++){
        if(s[i] == a) ans++;
    }
    return ans;
}
int main(){
    cin >> t;
    for(int i=2 ; i<=10001 ; i++) s[i] = 0;
    s[1] = 1;
    while(t--){
        cin >> n >> a;      
        for(int i=2 ; i<=n ; i++){
            for(int j=1 ; j<=ls ; j++){
                s[j] *= i;
            }
            for(int j=1 ; j<=ls ; j++){
                s[j+1] += s[j]/10;
                s[j] %= 10;
                if(j == ls) ls++;
            }
        }
        for(int i=ls ; i>=1 ; i--){
            cout << s[i];
        }cout << endl;
//      cout << times(s) << endl;
    }
    return 0;
}

by ud2_ @ 2020-11-03 09:21:32

@fussyguy

 using namespace std;
 int t;
 int n,a;
-int ls=1;
+int ls;
 int s[10001];
 int times(int s[]){
     int ans=0;
 }
 int main(){
     cin >> t;
-    for(int i=2 ; i<=10001 ; i++) s[i] = 0;
-    s[1] = 1;
     while(t--){
+        ls = 1;
+        for(int i=2 ; i<=10001 ; i++) s[i] = 0;
+        s[1] = 1;
         cin >> n >> a;      
         for(int i=2 ; i<=n ; i++){
             for(int j=1 ; j<=ls ; j++){
                 s[j] *= i;
             }
             for(int j=1 ; j<=ls ; j++){
+                if (s[j] < 10)
+                    continue;
                 s[j+1] += s[j]/10;
                 s[j] %= 10;
                 if(j == ls) ls++;

by fussyguy @ 2020-11-03 12:44:30

@sjx233_ 可想而知,有一个大佬朋友多么幸福,i了i了


by fussyguy @ 2020-11-03 12:46:03

@sjx233_ 非常感谢啊,我会了


|