Description
The game Minesweeper is played on an n by n grid. In this grid are hidden m mines, each at a distinct grid location. The player repeatedly touches grid positions. If a position with a mine is touched, the mine explodes and the player loses. If a positon not containing a mine is touched, an integer between 0 and 8 appears denoting the number of adjacent or diagonally adjacent grid positions that contain a mine. A sequence of moves in a partially played game is illustrated below.Output
Your output should represent the board, with each position filled in appropriately. Positions that have been touched and do not contain a mine should contain an integer between 0 and 8. If a mine has been touched, all positions with a mine should contain an asterisk. All other positions should contain a period.Sample Input
8 ...**..* ......*. ....*... ........ ........ .....*.. ...**.*. .....*.. xxx..... xxxx.... xxxx.... xxxxx... xxxxx... xxxxx... xxx..... xxxxx...
Sample Output
001..... 0013.... 0001.... 00011... 00001... 00123... 001..... 00123...
×¢Ò⣺Èç¹û²Èµ½µØÀ×£¬Òª°ÑËùÓеØÀ×±íʾ³öÀ´£»
#includeusing namespace std; #define MAX 12 int n; char map[MAX][MAX],ans[MAX][MAX]; int count(int i,int j,int n){ int ans=0; if (map[i-1][j-1]=='*' && i-1>=0 && j-1>=0) ans++; if (map[i-1][j]=='*' && i-1>=0) ans++; if (map[i-1][j+1]=='*' && i-1>=0 && j+1 =0) ans++; if (map[i][j]=='*') ans++; if (map[i][j+1]=='*' && j+1 =0) ans++; if (map[i+1][j]=='*' && i+1 >n){ for (int i=0;i >map[i][j]; int flag=0; for (int i=0;i >ans[i][j]; if (map[i][j]=='*' && ans[i][j]=='x') flag=1; if (ans[i][j]=='x'){ int k=count(i,j,n); ans[i][j]=k+'0'; } } } for (int i=0;i