Write a function named xRegions
that accepts a reference to a Grid
of characters as a parameter, where every character in the grid is guaranteed to be either an uppercase 'X'
or dash '-'
, and modify its state so that any dashes or groups of dashes that are entirely surrounded by Xes in the original grid will be changed to 'X'
themselves.
For example, suppose the grid contains the following characters:
Grid<char> board {
{'X', 'X', 'X', 'X', 'X', 'X', '-'},
{'X', '-', '-', '-', 'X', 'X', 'X'},
{'X', 'X', 'X', '-', 'X', 'X', 'X'},
{'X', '-', 'X', '-', 'X', '-', 'X'},
{'X', 'X', 'X', 'X', 'X', '-', 'X'},
{'X', '-', '-', 'X', 'X', '-', 'X'},
{'X', '-', '-', 'X', 'X', 'X', 'X'}
};
Then the call of xRegions(board);
should modify it to store the following:
{
{'X', 'X', 'X', 'X', 'X', 'X', '-'},
{'X', 'X', 'X', 'X', 'X', 'X', 'X'},
{'X', 'X', 'X', 'X', 'X', 'X', 'X'},
{'X', 'X', 'X', 'X', 'X', 'X', 'X'},
{'X', 'X', 'X', 'X', 'X', 'X', 'X'},
{'X', '-', '-', 'X', 'X', 'X', 'X'},
{'X', '-', '-', 'X', 'X', 'X', 'X'}
}
Notice that two groups of dashes are not changed to 'X'
: the ones that touch the top-right and bottom borders of the grid.
Your code should work for a board of any size, even one with 0 rows or columns.
You may assume that no characters appear in the board other than 'X'
and '-'
.