DWITE Online Computer Programming Contest
October 2005

Problem 4

Minesweeper

Minesweeper is a game available with the Windows™ operating system. The object of Minesweeper is to locate all the mines as quickly as possible without uncovering any of them. You can uncover a square by clicking it. If you uncover a mine, you lose the game. If a number appears on a square, it indicates how many mines are in the eight squares that surround the numbered one.

Sometimes clicking on a square that has no mines surrounding it reveals many squares. It will reveal all of the squares surrounding it until it reaches squares that have mines surrounding it.

Your job is to write a program to determine the result of clicking on a square during a Minesweeper game.

The input will contain 21 lines of data. The first 16 lines will contain 30 characters each. Each character will be either an 'X' that will represent a square with a mine, or a period '.' that will represent a square without a mine. The last five lines will each contain two integers, r and c, that represent the row and column of the square that is clicked. Assume the top left square of the minefield to be at row one and column one.

The output will contain the results of clicking on the square. For the sake of simplicity, assume that each of the clicks from the input is the first click of a new game. If the square contains a mine, output "MINE - YOU LOST". If the square does not contain a mine, but there are some mines surrounding it, output "NO MINE - # SURROUNDING IT", where # is the number of mines surrounding it. If the square does not contain a mine and there are no mines surrounding it, output "NO MINES - # SQUARES REVEALED", where # is the number of squares revealed. Note that the characters in the output are uppercase.

Sample Input

.....XXX.............X...X...X
..........XX...X......X.......
....X.X.......................
.............X...X......XXXX..
X....X.....X...X...X.......X..
X.X....X........X.X..X..X.X.X.
...X..X..........X.X...X..XX..
..X...X.......X.........X...X.
....XXXXX.................X...
.X.X.........X..........XX..X.
..XXXX...X.X............X.....
...XX...X.XX...X........X.X...
XXXX.X..XX....X...............
.........X.X...X...........X..
X.X.X.XX.....X..X.X...X..X..XX
..X.........X...............X.
1 6
3 8
6 2
10 18
16 29

Sample Output

MINE - YOU LOSE
NO MINE - 1 SURROUNDING IT
NO MINE - 3 SURROUNDING IT
NO MINE - 72 SQUARES REVEALED
MINE - YOU LOSE

All Submissions
Best Solutions


Point Value: 10 (partial)
Time Limit: 1.00s
Memory Limit: 32M
Added: Mar 06, 2009

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

In the question info it says
If the square contains a mine, output "MINE - YOU LOST"


But in the sample output it says
MINE - YOU LOSE


Please clarify which one it is