力扣第999题 车的可用捕获量
![](https://img2020.cnblogs.com/blog/384305/202003/384305-20200326221057474-568648207.png)
![](https://img2020.cnblogs.com/blog/384305/202003/384305-20200326221106617-1322687059.png)
class Solution {
public:
int numRookCaptures(vector<vector<char>>& board) {
int num = 0;
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
if (board[i][j] == 'R')
{
int temp = 1;
while(i - temp >=0 && board[i - temp][j] != 'B')
{
if (board[i - temp][j] == 'p'){num++;break;}
temp++;
}
temp = 1;
while (i + temp < 8 && board[i + temp][j] != 'B')
{
if (board[i + temp][j] == 'p'){num++;break;}
temp++;
}
temp = 1;
while (j - temp >= 0 && board[i][j - temp] != 'B')
{
if (board[i][j - temp] == 'p'){num++;break;}
temp++;
}
temp = 1;
while (j + temp < 8 && board[i][j + temp] != 'B')
{
if (board[i][j + temp] == 'p'){num++;break;}
temp++;
}
return num;
}
}
}
return num;
}
};