Matrices and grids · 14 / 15 Exercise Hard

Paint bucket

Objective

The paint bucket tool of an image editor changes the colour of a square and of every connected square (horizontally or vertically) that had that same colour. It is a flood fill over a grid.

Instructions

  • The first line has rows f and columns c; then come f lines of c characters (each character is a colour); and finally a line with i j colour: the square where you click and the new colour.
  • Show the resulting grid. If the new colour is already the one of the square, nothing changes.
Input
3 4
1100
1010
0011
0 0 5
Output
5500
5010
0011

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise