题解 | #小红的好数#

小红的好数

https://www.nowcoder.com/practice/de234d0d61d549c6a436e9509dbeea11

分析

由于数据限制n<1e6那么直接暴力就行了,从98765开始搜就行了

代码

#include "bits/stdc++.h"

using namespace std;
#define int long long
#define endl "\n"
#define PII pair<int,int>
#define PIII pair<int,PII>
const int MOD = 1e9 + 7;
const int N = 3e5;

bool check(int n) {
    map<char, int> a;
    if (n < 10000)a['0']++;
    string t = to_string(n);
    for (int i = 0; i < t.size(); i++) {
        if (a[t[i]])return false;
        a[t[i]]++;
    }
    return true;
}

void slu() {
    int n = 98766;
    int cnt = 0;
    int k;
    cin >> k;
    while (n--) {
        if (check(n))cnt++;
        if (cnt == k) {
            string t = to_string(n);
            int l = t.size();
            for (int i = 5 - l; i > 0; i--)cout << "0";
            cout << t;
            return;
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T;
//    cin >> T;
    T = 1;
    while (T--)slu();

}

全部评论

相关推荐

大飞的诡术妖姬:之前看b站多明海有个说法,日本就业竞争非常低的原因不光是毕业学生少,还有很多人干两年不喜欢职场氛围就辞职躺平,位置也空了很多,论吃苦耐劳还得看咱们
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务