We consider a positive integer perfect, if and only if the sum of its digits is exactly 10. Given a positive integer k, your task is to find the k-th smallest perfect positive integer.
Input
A single line with a positive integer k (1 ≤ k ≤ 10 000).
Output
A single number, denoting the k-th smallest perfect integer.
Examples
Input
1
Output
19
Input
2
Output
28
Note
The first perfect integer is 19 and the second one is 28.
暴力破解,
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int k;
long long a[10010];//用数据大的时候直接用ll
scanf("%d",&k);
for(long long int m=19,i=1;i<=10000;m++)
{
int sum=0;
long long n=m;//数据类型要保持一致
while(n){
sum+=n%10;
n=n/10;
}
if(sum==10) a[i]=m,i++;
}
printf("%lld\n",a[k]);//输出时注意类型
return 0;
}
从这里知道了如何简洁的输出各个位上的数
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
long long i;
scanf("%lld",&i);
int c=0;
while(i){
printf("%lld ",i%10);
i/=10;
c++;
}
printf("\n");
printf("位数:%d\n",c);
return 0;
}