An image can be represented as a grid of black and white cells. An object in the image is defined as a group of connected black cells that touch on one side (Please note: cells are not connected if they only touch at a corner). They must touch along their sides. The diagram below represents an image that contains two objects, therefore, and one of them consists of a single cell.
Many drawing or graphic programs include erasing features. With such an eraser tool, an object can be completely erased by double-clicking on that object with a mouse.
This problem involves erasing an object stored as a collection of black squares in a matrix image.
-
The first entry in the provided text file (digital.txt) is the number of pairs that follow (i.e., 55). Each subsequent line contains a pair of integers, separated by a blank space. Each pair is a row and column coordinate that specifies the location of a black cell in the starting grid. The row and column values range from 0 to 19.
-
Write a program that accomplishes the following:
-
Load the text file digital.txt representing the 20 x 20 grid of black and white squares.
-
Ask the user for the starting coordinate of an attempted erasure. If this starting coordinate is part of an object, the program should erase the entire object (change black to white).
-
Print out the grid afterwards.
-
The left hand image is the result of loading the data from digital.txt. After loading the data file, print out the image.
-
Erase any one of the objects; print out the remaining two objects.
- Erase any one of the remaining two objects; print out the single remaining object. (NOTE: Row and column values in pictures should be from 0 to 19)