-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathb.java
30 lines (28 loc) · 928 Bytes
/
b.java
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
import java.io.*;
import java.util.*;
public class Program{
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter pw = new PrintWriter(System.out);
static StringTokenizer st = new StringTokenizer("");
public static void main(String args[]) throws IOException{
int T = Integer.parseInt(next());
while(T-- > 0){
long N = Integer.parseInt(next());
long x = 1;
int ans = 0;
while(x <= N){
for(long i = 1; i < 10; i++){
if(i * x > N) break;
ans++;
}
x = x * 10 + 1;
}
pw.println(ans);
}
br.close(); pw.close();
}
static String next() throws IOException{
while(!st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
return st.nextToken();
}
}