Minesweeper
InterviewTime limit1sMemory limit1024 MB
Given a 3x3 grid marking bombs with 9, replace each non-bomb cell with the count of bombs in its up to eight neighboring cells.
- Level
Easy2 of 10
- Topics
- Implementation, Array, Brute force, Simulation
- Solved
- No attempts yet
Problem
Nasko likes to play the game Minesweeper on his computer. The game gives a square divided into 9 small cells, some of which contain a bomb. The player must write a number in every cell that has no bomb. The number must show how many bombs are in the neighboring cells (cells that share a vertex or a side).
Write a program minesweeper that reads the arrangement of bombs in the nine cells and prints the square with the numbers filled in.
Input
The first three lines of the standard input contain three integers each. Every integer is 0 or 9, where 9 marks the position of a bomb and 0 marks a position with no bomb (Fig. 1). The numbers are separated by a single space.

Fig. 1
Output
The standard output contains 3 lines with 3 integers each, showing the contents of the nine cells. In each position where the input had a 0, print the number of bombs surrounding that cell. The numbers are separated by a single space.