-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
41 lines (40 loc) · 813 Bytes
/
main.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
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
using namespace std;
class Solution {
public:
vector<int> lexicalOrder(int n) {
vector<int> res;
int cur = 1;
for(int i=1; i<=n; i++){
res.push_back(cur);
if(cur * 10 <= n){
cur *= 10;
}else{
if(cur >= n){
cur /= 10;
}
cur += 1;
while(cur % 10 == 0){
cur /= 10;
}
}
}
return res;
}
};
int main()
{
int n;
cin >> n;
Solution s;
vector<int> nums;
nums = s.lexicalOrder(n);
for(int i=0; i<nums.size(); i++){
cout << nums[i] << endl;
}
return 0;
}