-
Notifications
You must be signed in to change notification settings - Fork 0
/
J01018
32 lines (28 loc) · 805 Bytes
/
J01018
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
package test;
import java.util.*;
import java.math.*;
public class J01018 {
public static Boolean Check(String s) {
int n = s.length();
int d = s.charAt(0) - '0';
for (int i = 1; i < n; i++) {
d += s.charAt(i) - '0';
if (Math.abs(s.charAt(i) - s.charAt(i - 1)) != 2)
return false;
}
if (d % 10 != 0)
return false;
return true;
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- >0){
long n = sc.nextLong();
if (Check(Long.toString(n)) == true)
System.out.println("YES");
else
System.out.println("NO");
}
}
}