aboutsummaryrefslogtreecommitdiff
path: root/week12/ex2.cpp
blob: e123ed3a5eb8716b91a2d3ba0d1e4c7637eaf365 (plain) (blame)
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
#include <iostream>

void floodFill(int row, int col, char** board, int rows, int cols) {
	if (row < 0 || row >= rows || col < 0 || col >= cols || board[row][col] == '#')
		return;

	board[row][col] = '#';
	floodFill(row+1, col,   board, rows, cols); // up
	floodFill(row-1, col,   board, rows, cols); // down
	floodFill(row,   col+1, board, rows, cols); // right
	floodFill(row,   col-1, board, rows, cols); // left
}

int main() {
	int N, M;
	std::cin >> N >> M;

	char** board = new char*[N];
	for (int i = 0; i < N; i++) {
		board[i] = new char[M];
	}

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			std::cin >> board[i][j];
		}
	}

	int X, Y;
	std::cin >> X >> Y;

	floodFill(X, Y, board, N, M);

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			std::cout << board[i][j] << " ";
		}
		std::cout << std::endl;
	}

	for (int i = 0; i < N; i++) {
		delete[] board[i];
	}
	delete[] board;
}