题面:
给你一个整数k (1≤k≤10000 )
求第k 小的各个数位上的数加起来为10的数
题解:
这道题数据最大只有10000,直接从头开始枚举不会超时,所以我就直接暴力枚举了,AC。 代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int s,cnt,t,ans;
ans=0;
s=18;//小优化,从18开始枚举
while (ans!=n)//枚举到第n个就跳出
{
s++;//s用来枚举
cnt=0;//cnt存放s的数字和
t=s;//替身变量
while (t!=0)//求s的数字和
{
cnt+=t%10;
t/=10;
}
//cout<<cnt<<endl;
if (cnt==10)//判断数字和是否为10
{
ans++;
}
}
cout<<s<<endl;
return 0;
}