From Skiena and Revilla, Programming Challenges: The Springer-Verlag, New York, 2003. ISBN: 0-387-00163-8.
110102
Programming Contest Training Manual
Minesweeper
Have you ever played Minesweeper? This ute little game omes with a ertain operating system whose name we an't remember. The goal of the game is to nd where all the mines are lo ated within a M N eld. The game shows a number in a square whi h tells you how many mines there are adja ent to that square. Ea h square has at most eight adja ent squares. The 4 4 eld on the left ontains two mines, ea h represented by a \*" hara ter. If we represent the same eld by the hint numbers des ribed above, we end up with the eld on the right: *... .... .*.. ....
*100 2210 1*10 1110
Input
The input will onsist of an arbitrary number of elds. The rst line of ea h eld ontains two integers n and m (0 < n; m 100) whi h stand for the number of lines and olumns of the eld, respe tively. Ea h of the next n lines ontains exa tly m hara ters, representing the eld. Safe squares are denoted by \." and mine squares by \*," both without the quotes. The rst eld line where n = m = 0 represents the end of input and should not be pro essed. Output
For ea h eld, print the message Field #x: on a line alone, where x stands for the number of the eld starting from 1. The next n lines should ontain the eld with the \." hara ters repla ed by the number of mines adja ent to that square. There must be an empty line between eld outputs. Sample Input
Sample Output
4 4 *... .... .*.. .... 3 5 **... ..... .*... 0 0
Field #1: *100 2210 1*10 1110 Field #2: **100 33200 1*100
http://www.programming- hallenges. om
2003
opyright