-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJ03021.java
61 lines (55 loc) · 1.48 KB
/
J03021.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.util.*;
import java.math.*;
public class J03021 {
public static String[] a = new String[10];
public static boolean solve(String s) {
int l = 0;
int r = s.length() - 1;
while (l <= r) {
int checkl = 0;
int checkr = 0;
char left = s.charAt(l);
char right = s.charAt(r);
for (int i = 2; i <= 9; i++) {
for (char x : a[i].toCharArray()) {
if (left == x) {
checkl = i;
}
if (right == x) {
checkr = i;
}
}
}
if (checkl != checkr) {
return false;
}
l++;
r--;
}
return true;
}
public static void start() {
a[2] = "ABC";
a[3] = "DEF";
a[4] = "GHI";
a[5] = "JKL";
a[6] = "MNO";
a[7] = "PQRS";
a[8] = "TUV";
a[9] = "WXYZ";
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
sc.nextLine();
start();
while (t-- > 0) {
String s = sc.nextLine();
if (solve(s.toUpperCase())) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
}