-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJ01010
36 lines (33 loc) · 1.01 KB
/
J01010
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
package test;
import java.util.*;
public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
String n = sc.next();
cut(n);
}
}
public static void cut(String s) {
String x = "";
if(s.charAt(0)!='0' && s.charAt(0)!='1' && s.charAt(0)!='8' && s.charAt(0)!='9') {
System.out.println("INVALID");
}
else {
int i=0;
while(i < s.length() && s.charAt(i)!='1') i++;
while(i < s.length()){
if(s.charAt(i)=='1') x = x + '1';
else if(s.charAt(i)=='0' || s.charAt(i)=='8' || s.charAt(i)=='9') x = x + '0';
else{
x = "";
break;
}
i++;
}
if(x=="") System.out.println("INVALID");
else System.out.println(x);
}
}
}