-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
How Many X's.cpp
56 lines (55 loc) · 1.48 KB
/
How Many X's.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
/*Given an integer X within the range of 0 to 9, and given two positive integers as upper and lower bounds respectively, find the number of times X occurs as a digit in an integer within the range, excluding the bounds. Print the frequency of occurrence as output.
Input:
The first line of input is an integer T, denoting the number of test cases. For each test case, there are two lines of input, first consisting of the integer X, whose occurrence has to be counted. Second, the lower and upper bound, L and U which are positive integers, on the same line separated by a single space, respectively.
Output:
For each test case, there is only one line of output, the count of the occurrence of X as a digit in the numbers lying between the lower and upper bound, excluding them.
Constraints:
1<=T<=100
0<=X<=9
0<L<U<=10^5
Example:
Input
5
3
100 250
2
10000 12345
0
20 21
9
899 1000
1
1100 1345
Output:
35
1120
0
120
398
Explanation:
In the first test case, the occurrence of 3 in the numbers starting from 101 to 249 is counted and comes out to be 35. */
//SUMIT KUMAR
#include<iostream>
using namespace std;
int main()
{
int T;
cin>>T;
while(T--)
{
int x, s, u, k=0;
cin>>x>>s>>u;
for(int i=s+1;i<u;i++)
{
int n=i;
while(n)
{
if((n%10)==x)
k++;
n=n/10;
}
}
cout<<k<<endl;
}
return 0;
}