为啥全WA了啊,感觉没问题啊

P1591 阶乘数码

yawningking @ 2023-03-03 19:03:39

#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<iomanip>
using namespace std;
int main() {
    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        int n;
        cin >> n;
        int  l = 1;
        for (int j = n; j > 1; j--) {
            l = l * j;
        }
        int a;
        cin >> a;
        string s1 = l + "";
        int ans = 0;
        for (int k = 0; k < s1.length(); k++) {
            if (s1[k] == a) {
                ans++;
            }
            cout << ans << endl;
        }
    }
    return 0;
}

P1591 阶乘数码


by famous_zhang @ 2023-03-11 15:52:34

  1. 要用高精,n<=1000。
  2. int 不能直接换成string

by yawningking @ 2023-03-15 21:17:31

@AlbertYue 谢谢您!


|