12999 - Minesweeper   

Description

Write a program to input an H x W array of 0’s and 1’s where H and W are also user inputs.  You may assume that both H and W are non-zero and at most 10.  The array represents an H x W minefield so that a cell with a 1 (resp. 0) means the cell contains (does not contain) a bomb.  Your program should print the minefield as follows:

  1. If a cell contains a bomb, print a ‘#’.
  2. If a cell does not contain a bomb and is not adjacent to any bomb, print a ‘.’

  3. Otherwise, print the number of neighboring bombs.

Input

 

  • The first input, H and W, is the size of the HxW array.

  • Next H lines will be the elements of the array.

Output

Output a HxW array

  • If a cell contains a bomb, print a ‘#’.
  • If a cell does not contain a bomb and is not adjacent to any bomb, print a ‘.’
  • Otherwise, print the number of neighboring bombs.

Sample Input  Download

Sample Output  Download

Tags




Discuss