-
Notifications
You must be signed in to change notification settings - Fork 0
/
1038_real.cpp
43 lines (39 loc) · 881 Bytes
/
1038_real.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<string> dec_num;
void create_dec(string &cur_dec,int need_size){
int size = cur_dec.size();
if(size == need_size){
dec_num.push_back(cur_dec);
return;
}
int last_num = cur_dec[size-1] - '0';
for(int i=0;i<last_num;i++){
cur_dec.push_back(i+'0');
create_dec(cur_dec,need_size);
cur_dec.pop_back();
}
}
int main(){
int n,size;
cin >> n;
dec_num.push_back(to_string(0));
for(int i=1;i<10;i++){
for(int j=1;j<=9;j++){
string start = to_string(j);
create_dec(start,i);
}
}
dec_num.push_back("9876543210");
size = dec_num.size();
if(n >= size){
cout << "-1\n";
}
else{
cout << dec_num[n] << '\n';
}
return 0;
}