-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathavailableCapturesForRook999.cpp
More file actions
55 lines (55 loc) · 1.89 KB
/
Copy pathavailableCapturesForRook999.cpp
File metadata and controls
55 lines (55 loc) · 1.89 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
class Solution {
public:
int numRookCaptures(vector<vector<char>>& board) {
int i, j, count = 0;
for (int a = 0; a < board.size(); a++) {
for (int b = 0; b < board[a].size(); b++) {
if (board[a][b] == 'R') {
i = a; j = b;
while (i-1 > -1) {
i--;
if (board[i][j] == 'B') {
break;
} else if (board[i][j] == 'p') {
count++;
//cout <<"up "<<endl;
break;
}
}
i = a;
while (i+1 < board.size()) {
i++;
if (board[i][j] == 'B') {
break;
} else if (board[i][j] == 'p') {
cout <<"down "<<endl;
count++;break;
}
}
i = a;
while (j+1 < board[0].size()) {
j++;
if (board[i][j] == 'B') {
break;
} else if (board[i][j] == 'p') {
//cout <<"right "<<endl;
count++;break;
}
}
j = b;
while (j-1 > -1) {
j--;
if (board[i][j] == 'B') {
break;
} else if (board[i][j] == 'p') {
//cout <<"left "<<endl;
count++;break;
}
}
return count;
}
}
}
return 0;
}
};