forked from zapellass123/OpenEmailGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLexicograhical Order.cpp
More file actions
72 lines (60 loc) · 758 Bytes
/
Lexicograhical Order.cpp
File metadata and controls
72 lines (60 loc) · 758 Bytes
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
Given a number n, print numbers from 1 to n in dictionary(lexicographical) order.
Sample Input
20
Sample Output
1
10
11
12
13
14
15
16
17
18
19
2
20
3
4
5
6
7
8
9
*/
#include <iostream>
#include <string>
using namespace std;
/*
int csti(string s){
int ans=0;
for(int i=0;i<s.size();i++)
ans=ans*10+(s[i]-48);
return ans;
}
*/
void help(int x,int n){
if(x>n)
return;
for(int i=0;i<=9;i++){
x=x*10+i;
if(x==0)
continue;
if(x<=n)
cout<<x<<endl;
help(x,n);
x=(x-i)/10;
}
}
void lexicographicalOrder(int num){
// Write your code here
int x=0;
help(x,num);
}
int main() {
int n;
cin >> n;
lexicographicalOrder(n);
}