题解 | #小红的好数#

小红的好数

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();

}

全部评论

相关推荐

神哥了不得:你简历字体有点不太协调呀,下面的字实在太小了呀,而且项目也不太行,建议换几个高质量的项目,面试会多很多
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务