-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1520B.cpp
More file actions
40 lines (35 loc) · 817 Bytes
/
1520B.cpp
File metadata and controls
40 lines (35 loc) · 817 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
#include <bits/stdc++.h>
using namespace std;
bool least(int f, int first, int po) {
int temp = 0;
for (int i = 0; i < po; i++) {
temp = temp * 10 + first;
}
return f >= temp;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int po = to_string(n).size() - 1;
if (po == 0) {
cout << n << '\n';
}
else if (n == (int)pow(10, po)) {
cout << 9 * po << '\n';
}
else {
int ans = 9 * po;
int x = (int)pow(10, po);
int first = n / x;
ans += first - 1;
int f = n % x;
if (least(f, first, po)) ans++;
cout << ans << '\n';
}
}
}