![]() |
| find the count of all the stepping numbers in the range [n, m]. |
For each test case in a new line print an integer denoting the number of stepping numbers in the range between n and m.
Example:
Input:
3
0 21
10 15
0 1
Output:
13
2
2
Input:
3
0 21
10 15
0 1
Output:
13
2
2
#include <iostream>
using namespace std;
int test(int n) {
int i = n % 10;
n /= 10;
while (n > 0) {
if (abs(i - n % 10) != 1)
return 0;
i = n % 10;
n /= 10;
}
return 1;
}
int main() {
//code
int t;
cin >> t;
while (t--) {
int n, m, cnt = 0;
cin >> n >> m;
for (int i = n; i <= m; ++i) {
if (test(i))
++cnt;
}
cout << cnt << endl;
}
return 0;
}![find the count of all the stepping numbers in the range [n, m]. find the count of all the stepping numbers in the range [n, m].](https://cdn.pixabay.com/photo/2018/08/18/09/44/stairs-3614468_960_720.jpg)