-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathCodeForces_1462C_Unique_Number.java
More file actions
37 lines (35 loc) · 999 Bytes
/
CodeForces_1462C_Unique_Number.java
File metadata and controls
37 lines (35 loc) · 999 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
// AC: 171 ms
// Memory: 0 KB
// Greedy.
// T:O(t), S:O(1)
//
import java.util.Scanner;
public class CodeForces_1462C_Unique_Number {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt(), ret = 0;
for (int i = 0; i < t; i++) {
int x = sc.nextInt();
if (x > 45) {
ret = -1;
} else if (x < 10) {
ret = x;
} else {
StringBuilder sb = new StringBuilder();
int pos = 9;
while (x > 0) {
if (x >= pos) {
sb.append(pos);
x -= pos;
pos--;
} else {
sb.append(x);
break;
}
}
ret = Integer.parseInt(sb.reverse().toString());
}
System.out.println(ret);
}
}
}