2009: Mine Sweeper

内存限制:128 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:2 通过:2

题目描述

The gameMinesweeper is played on an n by n grid. In this grid are hidden m mines, eachat a distinct grid location. The player repeatedly touches grid positions. If aposition with a mine is touched, the mine explodes and the player loses. If apositon not containing a mine is touched, an integer between 0 and 8 appearsdenoting the number of adjacent or diagonally adjacent grid positions thatcontain a mine. A sequence of moves in a partially played game is illustratedbelow.

  

Here, n is 8, m is10, blank squares represent the integer 0, raised squares represent unplayedpositions, and the figures resembling asterisks represent mines. The leftmostimage represents the partially played game. From the first image to the second,the player has played two moves, each time choosing a safe grid position. Fromthe second image to the third, the player is not so lucky; he chooses aposition with a mine and therefore loses. The player wins if he continues tomake safe moves until only m unplayed positions remain; these must necessarilycontain the mines.

Your job is toread the information for a partially played game and to print the correspondingboard.

输入格式

The first line of input contains a single postitive integer n <= 10. Thenext n lines represent the positions of the mines. Each line represents thecontents of a row using n characters: a period indicates an unmined positonwhile an asterisk indicates a mined position. The next n lines are each ncharacters long: touched positions are denoted by an x, and untouched positionsby a period. The sample input corresponds to the middle figure above.

Input containsmultiple test cases. Process to the end of file.

输出格式

Your output should represent the board, with each position filled inappropriately. Positions that have been touched and do not contain a mineshould contain an integer between 0 and 8. If a mine has been touched, allpositions with a mine should contain an asterisk. All other positions shouldcontain a period.

Separate outputfor subsequent test cases with a single blank line.

输入样例 复制

8
...**..*
......*.
....*...
........
........
.....*..
...**.*.
.....*..
xxx.....
xxxx....
xxxx....
xxxxx...
xxxxx...
xxxxx...
xxx.....
xxxxx...

输出样例 复制

001.....
0013....
0001....
00011...
00001...
00123...
001.....
00123...

分类标签