Problem C
Reverse Minesweeper
Minesweeper is a popular game requiring skill and a little bit of luck. If youâ€™re not familiar with it, it involves a minefield with $x$ rows and $y$ columns. Each position of the field can have a mine or not. For example, this minefield has two mines:
However, the player cannot see where the mines are. Instead, she must select a position of the minefield; if the position has a mine, the game is over. If not, a number is revealed. This number indicates how many mines are present in the positions immediately adjacent to that position (including the diagonal ones). For example, the above board would contain the following numbers:
In a game of minesweeper, you would use those numbers to figure out where the mines are. However, you will be writing a program to perform a different task that requires no guesswork. You will be given the specification of a minefield, and the location of all the mines. Based on this information, you will need to compute the solved minefield with all the correct numbers in the positions that do not contain mines.
Input
The input contains the specification of a single minefield. The specification starts with a line with two nonzero positive integers, $x$ and $y$, that specify the dimensions of the minefield ($x$ is the number of rows, and $y$ is the number of columns; both are less than or equal to 100). This is followed by $x$ lines, each corresponding to a line of the minefield. Each of these lines has $y$ integers, each separated by a single space, corresponding to each column of that row. A one (1) denotes that there is a mine in that position, while a zero (0) denotes that there is no mine in that position.
Output
You will print the solved minefield according to the following specifications:

The solved minefield must be composed of $x$ lines, and each line must contain $y$ characters with no spaces between the characters.

If the solved position is a zero, print a hyphen ().

If the solved position is a nonzero number, print the number.

If the solved position is a mine, print an uppercase x (X).
Note that, for the sample data presented below, the first minefield corresponds to the minefield shown in the figures above.
Sample Input 1  Sample Output 1 

4 4 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 
111 1X1 1121 1X 
Sample Input 2  Sample Output 2 

4 6 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 
1X 11111 2X1 X21 