CSE 423 : Computer Graphics Assignment 6 Floodfill Input: standard input Output: Standard Output Adapted from problem #785, Valladolid Online Judge. http://acm.uva.es/p/v7/785.html A contour is represented on a two dimensional grid as illustrated in the sample below. The contours are made of ‘X’. All the other points of the grid are represented by ‘.’ (To indicate void space) and marking characters. A grid zone is defined as the set of points enclosed within a closed contour such that any two zone points can be connected by a path which does not cross any contour and which has segments running vertically or horizontally. A zone is marked if it contains identical characters, called marking characters, different than void (‘.’) and the character used to draw the grid contours (‘X’). No zone can contain different marking characters. However, observe that while all the contours are drawn with the same character, the markings of different zones can be different. A zone is unmarked if it contains only voids. Any grid zone can be either marked or unmarked. Note that there is also an ‘outside zone’. Write a program to fill all the marked zones. A marked zone is filled with its marking character, as shown in the samples below. Input There will be only one grid as input as follows. On the first line, there will be two integers, n (number of lines in the grid) and m (number of cells on each line). 0 < n <=100, 0 < m <= 100. Then n lines will follow. Each line will contain exactly m characters. Output Print the painted grid. Each grid is output in the same format as it is read from the input. Sample Input 1 Sample Output 1 5 22 ..XXXXXXXXXXXXXXXXXXXX ..X......X...........X ..X.#.#..XXXXXXXX./..X ..X.............X....X ..XXXXXXXXXXXXXXXXXXXX ..XXXXXXXXXXXXXXXXXXXX ..X######X///////////X ..X######XXXXXXXX////X ..X#############X////X ..XXXXXXXXXXXXXXXXXXXX Sample Input 2 Sample Output 2 9 28 ...XXXXXXXXXXXX.......XXXXXX ..X.......#...XXX..XXX...X.X ..X..XX.........X..X.....X.X .X..X..X..XXXXXXX..XXXXXXX.. .X...XX...X................. ..X.......X..XXXX..XXXXXXXX. ...XX.....XXXX..X..X../...X. ....X...........X..X..../.X. ....XXXXXXXXXXXXX..XXXXXXXX. ...XXXXXXXXXXXX.......XXXXXX ..X###########XXX..XXX...X.X ..X##XX#########X..X.....X.X .X##X..X##XXXXXXX..XXXXXXX.. .X###XX###X................. ..X#######X..XXXX..XXXXXXXX. ...XX#####XXXX##X..X//////X. ....X###########X..X//////X. ....XXXXXXXXXXXXX..XXXXXXXX. Sample Input 3 Sample Output 3 11 16 ................ ................ ....XXXX........ ...X/...X....... ...X....XXXX.... ...X.../...X.... ...X....XXXX.... XXXX....X.....#. ....XXXX........ ..-.....X....... .........X...... ################ ################ ####XXXX######## ###X////X####### ###X////XXXX#### ###X///////X#### ###X////XXXX#### XXXX////X####### ----XXXX######## --------X####### ---------X######