-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm419.c
26 lines (22 loc) · 821 Bytes
/
m419.c
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
void removeShip(char** board, int boardSize, int* boardColSize, int x, int y) {
if (x < 0 || x >= boardSize || y < 0 || y >= boardColSize[0] || board[x][y] == '.') {
return;
}
board[x][y] = '.';
removeShip(board, boardSize, boardColSize, x + 1, y);
removeShip(board, boardSize, boardColSize, x - 1, y);
removeShip(board, boardSize, boardColSize, x, y + 1);
removeShip(board, boardSize, boardColSize, x, y - 1);
}
int countBattleships(char** board, int boardSize, int* boardColSize) {
int counter = 0;
for (int i = 0; i < boardSize; i++) {
for (int j = 0; j < boardColSize[0]; j++) {
if (board[i][j] == 'X') {
counter++;
removeShip(board, boardSize, boardColSize, i, j);
}
}
}
return counter;
}