forked from tarunsinghofficial/HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJumping Numbers.cpp
65 lines (57 loc) · 886 Bytes
/
Jumping Numbers.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
set<long long> s;
void jumpingnums(long long d, long long N)
{
if(d>N)
{
return;
}
if(d<=N)
{
s.insert(d);
}
long long mod = d%10;
long long num;
if(mod == 0)
{
num = d*10 + mod + 1;
jumpingnums(num, N);
}
else if(mod==9)
{
num = d*10 + mod - 1;
jumpingnums(num, N);
}
else
{
num = d*10 + mod - 1;
jumpingnums(num, N);
num = d*10 + mod + 1;
jumpingnums(num, N);
}
}
int main() {
//code
long long T, N, mod;
long long i;
cin>>T;
while(T--)
{
cin>>N;
for(i=1; i<=9; i++)
{
jumpingnums(i, N);
}
cout<<0<<" ";
for(auto itr = ::s.begin(); itr!=::s.end(); itr++)
{
cout<<(*itr)<<" ";
}
cout<<endl;
s.clear();
}
return 0;
}