-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJ01018.java
42 lines (40 loc) · 1.1 KB
/
J01018.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
import java.util.Scanner;
public class J01018 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
String s = sc.next();
if (sum(s)) {
Process(s);
}
else System.out.println("NO");
}
}
public static boolean sum(String s) {
int sum = 0;
char[] c = s.toCharArray();
for (int i = 0; i < s.length(); i++) {
sum += (int) c[i]-48;
}
if (sum%10==0)
return true;
return false;
}
public static void Process(String s) {
int tmp = 1;
char[] c = s.toCharArray();
for (int i = 1; i < s.length(); i++) {
if (Math.abs((int)c[i] - (int)c[i - 1] )==2) {
tmp = 0;
}
else {
tmp = 1;
break;
}
}
if (tmp == 0)
System.out.println("YES");
else System.out.println("NO");
}
}