-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ03024.java
More file actions
47 lines (44 loc) · 1.29 KB
/
J03024.java
File metadata and controls
47 lines (44 loc) · 1.29 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
package CODE_PTIT;
import java.util.*;
import java.lang.*;
public class J03024 {
public static int Check1(String s){
if(s.charAt(0) == '0') return 0;
for(int i = 0; i < s.length(); i++){
if((s.charAt(i) - '0') < 0 || (s.charAt(i) - '0') > 9) return 0;
}
return 1;
}
public static int Check(String s){
int cntL = 0, cntC = 0;
for(int i = 0; i < s.length(); i++){
if((s.charAt(i) - '0') % 2 == 0){
cntC++;
}
else cntL++;
}
if(cntC < cntL && s.length() % 2 != 0){
return 1;
}
else if(cntC > cntL && s.length() % 2 == 0){
return 1;
}
else return 0;
}
public static void main(String[] args) {
Scanner inp = new Scanner(System.in);
int t = Integer.parseInt(inp.nextLine());
while(t-- > 0){
String s = inp.nextLine();
if(Check(s) == 1 && Check1(s) == 1){
System.out.printf("YES\n");
}
else if(Check1(s) == 0){
System.out.println("INVALID");
}
else{
System.out.println("NO");
}
}
}
}