题解 | #小红的好数#
小红的好数
https://www.nowcoder.com/practice/de234d0d61d549c6a436e9509dbeea11
#include<bits/stdc++.h> // 这题真放比赛上难度应该 周赛BC题 感觉差不多
#include <iostream>
using namespace std;
#define int long long
const int N=100000;// 最大上限
int a[10]={0};
bool check(int x)
{
char c='0';
memset(a,0,sizeof(a)); /// 数组a重置
string ss=to_string(x); // 把数字转换为字符串
while(ss.size()<5)
ss=c+ss;
for(int i=0;i<5;i++)
{
a[ss[i]-'0']++;
if(a[ss[i]-'0']>1) // 判断是否有两个相同的数字
return 0;
}
return 1;// 满足条件
}
signed main() {
ios::sync_with_stdio(); // 加速
cin.tie(0);cout.tie(0);
int a, b;
int k;
cin>>k;// 第k大
for(int i=N;i>=1;i--)
{
if(check(i))// 判断
{
k--;
if(k==0)
{
string s=to_string(i);// 把输出的数字转化为字符串
char cc='0';
while(s.size()<5)/// 补充前导0
s=cc+s;///
cout<<s; // 输出
return 0;
}
}
}
}
// 64 位输出请用 printf("%lld")
