-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCapturesOfRook.java
More file actions
55 lines (50 loc) · 1.38 KB
/
CapturesOfRook.java
File metadata and controls
55 lines (50 loc) · 1.38 KB
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
public class CapturesOfRook {
public static void main(String[] args){
// AC 了
}
public int numRookCaptures(char[][] board){
int RRow = 0, RCol = 0;
boolean find = false;
for(int i = 0; i < board.length; i++){
for(int j = 0; j < board[0].length; j++){
if(board[i][j] == 'R'){
RRow = i;
RCol = j;
find = true;
break;
}
}
if(find) break;
}
int res = 0;
for(int i = RRow; i>=0; i--){
if(board[i][RCol] == 'B') break;
else if(board[i][RCol] == 'p') {
res ++;
break;
}
}
for(int i = RRow; i<board.length; i++){
if(board[i][RCol] == 'B') break;
else if(board[i][RCol] == 'p') {
res ++;
break;
}
}
for(int j = RCol; j<board[0].length; j++){
if(board[RRow][j] == 'B') break;
else if(board[RRow][j] == 'p') {
res ++;
break;
}
}
for(int j = RCol; j>=0; j--){
if(board[RRow][j] == 'B') break;
else if(board[RRow][j] == 'p') {
res ++;
break;
}
}
return res;
}
}