Guest User

Minesweeper problem

a guest
Aug 18th, 2012
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. Have you ever played Minesweeper? This cute little game comes with a certain operating
  2. system whose name we can’t remember. The goal of the game is to find where
  3. all the mines are located within a M × N field.
  4. The game shows a number in a square which tells you how many mines there are
  5. adjacent to that square. Each square has at most eight adjacent squares. The 4×4 field
  6. on the left contains two mines, each represented by a “*” character. If we represent the
  7. same field by the hint numbers described above, we end up with the field shown below:
  8. *...
  9. ....
  10. .*..
  11. ....
  12.  
  13. *100
  14. 2210
  15. 1*10
  16. 1110
  17.  
  18. Input
  19. The input will consist of an arbitrary number of fields. The first line of each field
  20. contains two integers n and m (0 < n,m ≤ 100) which stand for the number of lines
  21. and columns of the field, respectively. Each of the next n lines contains exactly m
  22. characters, representing the field.
  23. Safe squares are denoted by “.” and mine squares by “*,” both without the quotes.
  24. The first field line where n = m = 0 represents the end of input and should not be
  25. processed.
  26. Output
  27. For each field, print the message Field #x: on a line alone, where x stands for the
  28. number of the field starting from 1. The next n lines should contain the field with the
  29. “.” characters replaced by the number of mines adjacent to that square. There must
  30. be an empty line between field outputs.
  31. Sample Input
  32. 4 4
  33. *...
  34. ....
  35. .*..
  36. ....
  37. 3 5
  38. **...
  39. .....
  40. .*...
  41. 0 0
  42. Sample Output
  43. Field #1:
  44. *100
  45. 2210
  46. 1*10
  47. 1110
  48. Field #2:
  49. **100
  50. 33200
  51. 1*100
Advertisement
Add Comment
Please, Sign In to add comment