-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJ01010.java
30 lines (28 loc) · 866 Bytes
/
J01010.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
30
import java.util.Scanner;
public class J01010 {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int t= scan.nextInt();
while (t-->0) {
String s = scan.next();
s = Cat_doi(s);
if (s != "INVALID") {
System.out.println(Long.parseLong(s));
}
else System.out.println(s);
}
}
public static String Cat_doi(String s){
char[] a=s.toCharArray();
String x="";
for(int i=0;i<s.length();i++){
if(a[i]!='0'&&a[i]!='1'&&a[i]!='8'&&a[i]!='9')return "INVALID";
if(a[i]=='0'||a[i]=='8'||a[i]=='9')x+="0";
else x+="1";
}
char[] b=x.toCharArray();
for(int i=0;i<x.length();i++)
if(b[i]!='0')return x;
return "INVALID";
}
}