forked from sureshmangs/Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1520B - Ordinary Numbers.cpp
106 lines (72 loc) · 1.48 KB
/
1520B - Ordinary 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
Let's call a positive integer n ordinary if in the decimal notation all its digits are the same. For example, 1, 2 and 99 are ordinary numbers, but 719 and 2021 are not ordinary numbers.
For a given number n, find the number of ordinary numbers among the numbers from 1 to n.
Input
The first line contains one integer t (1=t=104). Then t test cases follow.
Each test case is characterized by one integer n (1=n=109).
Output
For each test case output the number of ordinary numbers among numbers from 1 to n.
Example
inputCopy
6
1
2
3
4
5
100
outputCopy
1
2
3
4
5
18
*/
/*
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
vector <long long> v;
for (int i = 1; i <= 9; i++) {
string s = "";
for (int j = 1; j <= 9; j++) {
s += (i + '0');
v.push_back(stoi(s));
}
}
while (t--) {
int n;
cin >> n;
int res = 0;
for (auto &x: v) {
if (x <= n) res++;
}
cout << res << endl;
}
return 0;
}*/
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int res = 0;
for (int i = 1; i <= 9; i++) {
for (long long num = i; num <= n; num = num * 10 + i) {
res++;
}
}
cout << res << endl;
}
return 0;
}