Question: Minesweeper Programming challenge description: You will be given an M * N matrix. Each item in this matrix is either a ' * ' or

Minesweeper
Programming challenge description:
You will be given an M*N matrix. Each item in this matrix is either a '*' or a '.'. A '*' indicates a mine, whereas a '.' does not. The objective of the challenge is to output a M*N matrix where each element contains a number (except the positions which actually contain a mine which will remain as '*') which indicates the number of mines adjacent to it. Notice that each position has at most 8 adjacent positions e.g. left, top left, top, top right, right, ...
In the first sample test case, the matrix:
**.........*...
becomes
**100332001*100
Input:
Your program should read lines from standard input. Each line contains M,N, a semicolon and the M*N matrix in row major form.
Output:
Print out the new M*N matrix (in row major form) with each position(except the ones with the mines) indicating how many adjacent mines are there.
Test 1
Test InputDownload Test 1 Input
3,5;**.........*...
Expected OutputDownload Test 1 Output
**100332001*100
Test 2
Test InputDownload Test 2 Input
4,4;*........*......
Expected OutputDownload Test 2 Output
*10022101*101110

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!