/**
* @author xnl
* @Description:
* @date: 2022/7/31 21:41
*/
public class Solution {
public static void main(String[] args) {
Solution solution = new Solution();
char[][] borad = {{'.','.','.','.','.','.','.','.'},{'.','.','.','p','.','.','.','.'},{'.','.','.','R','.','.','.','p'},
{'.','.','.','.','.','.','.','.'},{'.','.','.','.','.','.','.','.'},
{'.','.','.','p','.','.','.','.'},{'.','.','.','.','.','.','.','.'},{'.','.','.','.','.','.','.','.'}};
System.out.println(solution.numRookCaptures(borad));
}
public int numRookCaptures(char[][] board) {
int x = 0, y = 0;
int n = board.length, m = board[0].length;
out: for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
if (board[i][j] == 'R'){
x = i;
y = j;
break out;
}
}
}
int ans = 0;
int temp = x - 1;
while (temp >= 0 ){
if (board[temp][y] == 'p'){
ans++;
break;
} else if (board[temp][y] == 'B'){
break;
}
temp--;
}
temp = x + 1;
while (temp < n ){
if (board[temp][y] == 'p'){
ans++;
break;
} else if (board[temp][y] == 'B'){
break;
}
temp++;
}
temp = y - 1;
while (temp >= 0 ){
if (board[x][temp] == 'p'){
ans++;
break;
} else if (board[x][temp] == 'B'){
break;
}
temp--;
}
temp = y + 1;
while (temp < m ){
if (board[x][temp] == 'p'){
ans++;
break;
} else if (board[x][temp] == 'B'){
break;
}
temp++;
}
return ans;
}
}