-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask_6.java
51 lines (47 loc) · 1.85 KB
/
Task_6.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
package Task_acmp;
import java.util.*;
public class Task_6 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String strokeLine = sc.nextLine();
char[] masDigit = {'1', '2', '3', '4', '5', '6', '7', '8'};
char[] masLetter = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'};
int xOne = 9;
int yOne = 9;
int xTwo = 9;
int yTwo = 9;
if (strokeLine.length() < 5 || strokeLine.charAt(2) != '-') {
System.out.println("ERROR");
} else {
for (int i = 0; i < 8; i++) {
if (strokeLine.charAt(0) == masLetter[i]) {
xOne = i;
}
if (strokeLine.charAt(1) == masDigit[i]) {
yOne = i;
}
if (strokeLine.charAt(3) == masLetter[i]) {
xTwo = i;
}
if (strokeLine.charAt(4) == masDigit[i]) {
yTwo = i;
}
}
if (xOne == 9 || yOne == 9 || xTwo == 9 || yTwo == 9) {
System.out.println("ERROR");
} else {
if (xOne + 1 == xTwo & yOne + 2 == yTwo || xOne - 1 == xTwo & yOne + 2 == yTwo) {
System.out.println("YES");
} else if (xOne + 2 == xTwo & yOne + 1 == yTwo || xOne + 2 == xTwo & yOne - 1 == yTwo) {
System.out.println("YES");
} else if (xOne + 1 == xTwo & yOne - 2 == yTwo || xOne - 1 == xTwo & yOne - 2 == yTwo) {
System.out.println("YES");
} else if (xOne - 2 == xTwo & yOne + 1 == yTwo || xOne - 2 == xTwo & yOne - 1 == yTwo) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
}
}