-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathleapCode.cpp
More file actions
56 lines (43 loc) · 834 Bytes
/
leapCode.cpp
File metadata and controls
56 lines (43 loc) · 834 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
#include<bits/stdc++.h>
using namespace std;
bool isLeapCode(long n) {
// cout << n << endl;
if(n/10 == 0) {
return true;
}
bool leapCode = true;
int last = n%10;
n /= 10;
while(n > 0) {
int d = n%10;
if((last - d) == 1 || (d - last) == 1) {
last = d;
n /= 10;
continue;
}
else {
leapCode = false;
break;
}
}
return leapCode;
}
void printLeapCodes(long n) {
for(long i = 0; i <= n; i++) {
// cout << "*" << endl;
if(isLeapCode(i)) {
cout << i << " " ;
}
}
}
int main() {
int t;
cin >> t;
while(t--) {
long n;
cin >> n;
printLeapCodes(n);
cout << endl;
}
return 0;
}