-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCatDoi.java
More file actions
47 lines (43 loc) · 1.36 KB
/
Copy pathCatDoi.java
File metadata and controls
47 lines (43 loc) · 1.36 KB
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
import java.util.Scanner;
public class CatDoi {
public static void testcase() {
Scanner in = new Scanner(System.in);
String s = in.nextLine();
boolean check = true;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) != '0' && s.charAt(i) != '1' && s.charAt(i) != '8' && s.charAt(i) != '9') {
System.out.println("INVALID");
check = false;
}
}
String s1 = "";
if (check == true) {
for (int i = 0; i < s.length(); i++) {
switch (s.charAt(i)) {
case '0':
s1 += "0";
break;
case '1':
s1 += "1";
break;
case '8':
s1 += "0";
;
break;
case '9':
s1 += "0";
break;
}
}
long l = Long.parseLong(s1.substring(s1.indexOf("1")));
System.out.println(l);
}
}
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while (t-- > 0) {
CatDoi.testcase();
}
}
}