📄 3841934_ac_329ms_2628k.java
字号:
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;
public class Main {
private String[] board = new String[8];
private static int[][] mov = { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 },
{ 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } };
private LinkedList<String> ans = new LinkedList<String>();
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new Main().run();
}
private void run() {
Scanner in = new Scanner(System.in);
String start;
while (in.hasNext()) {
ans.clear();
for (int i = 0; i < 8; i++) {
board[i] = in.next();
}
start = in.next();
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if (board[i].charAt(j) == start.charAt(0)) {
for (int k = 0; k < 8; k++) {
int cnt = -1;
int x, y;
x = i;
y = j;
while (valid(x, y)) {
if (board[x].charAt(y) != '.') {
cnt++;
}
x += mov[k][0];
y += mov[k][1];
}
x = i;
y = j;
while (valid(x, y)) {
if (board[x].charAt(y) != '.') {
cnt++;
}
x += mov[7 - k][0];
y += mov[7 - k][1];
}
x = i;
y = j;
while (cnt != 0) {
x += mov[k][0];
y += mov[k][1];
if (!valid(x, y)) {
break;
}
if (board[x].charAt(y) == '.'
|| board[x].charAt(y) == start
.charAt(0)) {
cnt--;
} else {
if (cnt == 1) {
cnt--;
}
break;
}
}
if (cnt == 0) {
ans.add("" + (char) ('A' + i)
+ Integer.toString(j + 1) + "-"
+ (char) ('A' + x)
+ Integer.toString(y + 1));
}
}
}
}
}
if (ans.isEmpty()) {
System.out.println("No moves are possible");
} else {
Collections.sort(ans);
for (int i = 0; i < ans.size(); i++) {
System.out.println(ans.get(i));
}
}
System.out.println();
}
}
private boolean valid(int x, int y) {
// TODO Auto-generated method stub
return (x >= 0 && y >= 0 && x < 8 && y < 8);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -