本题关键在于将整形大批量的转为字符串不足5位的用0补齐
实现方法很多,个人推荐用 format 来格式化,但是目前牛客不支持c++20用不了
string s = format("{:05}", i);
所以考虑使用while,将不足5位的字符串前方补0即可
判断一个字符串是不是5种字符组成的可以直接记录其中的元素数量,实现方法很多
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 5;
int __t = 1, n;
vector<string> good;
bool ck(string s) {
map<char, int> mp;
for (auto i : s)
mp[i]++;
if (mp.size() == 5)
return 1;
return 0;
}
void solve() {
cin >> n;
for (int i = 99999; i >= 0; i--) {
// string s = format("{:05}", i);
string s = to_string(i);
while (s.length() < 5)
s = '0' + s;
if (ck(s))
good.push_back(s);
}
cout << good[n - 1] << '\n';
return;
}
int32_t main() {
#ifdef ONLINE_JUDGE
ios::sync_with_stdio(false);
cin.tie(0);
#endif
// cin >> __t;
while (__t--)
solve();
return 0;
}

京公网安备 11010502036488号