ZOJ-1862 Mine Sweeper
来源:互联网 发布:为linux添加引导 编辑:程序博客网 时间:2024/06/04 18:57
Mine Sweeper
Time Limit: 2 Seconds MemoryLimit: 65536 KB
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.
Input
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.
Output
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.
Sample Input
8
...**..*
......*.
....*...
........
........
.....*..
...**.*.
.....*..
xxx.....
xxxx....
xxxx....
xxxxx...
xxxxx...
xxxxx...
xxx.....
xxxxx...
Sample Output
001.....
0013....
0001....
00011...
00001...
00123...
001.....
00123...
————————————————————————————————————————————————————————————————
如果点到了地雷,需要在最后的结果中将是地雷的点都表示出来。
————————————————————————————————————————————————————————————————
#include <stdio.h>#include <string.h>char calculate(int r, int l);char map[10][10];int n;int main(){ int i, j, m, count; char touch[10][10]; char str[11]; char res[10][10]; count = 0; while(scanf("%d", &n) != EOF) { if(count) { printf("\n"); } else { count = 1; } for(i = 0; i < n; i++) { scanf("%s", str); for(j = 0; j < n; j++) {map[i][j] = str[j]; } } for(i = 0; i < n; i++) { scanf("%s", str); for(j = 0; j < n; j++) {touch[i][j] = str[j];res[i][j] = '.'; } } m = 0; for(i = 0; i < n; i++) { for(j = 0; j < n; j++) {if(touch[i][j] == 'x') { if(map[i][j] == '*') { m = 1; } else { res[i][j] = calculate(i, j); }} } } if(m) { for(i = 0; i < n; i++) {for(j = 0; j < n; j++) { if(map[i][j] == '*') { res[i][j] = '*'; }} } } for(i = 0; i < n; i++) { for(j = 0; j < n; j++) {printf("%c", res[i][j]); } printf("\n"); } } return 0;}char calculate(int r, int l){ char count = '0'; if(r-1 >= 0 && map[r-1][l] == '*') { count++; } if(r-1 >= 0 && l-1 >= 0 && map[r-1][l-1] == '*') { count++; } if(l-1 >= 0 && map[r][l-1] == '*') { count++; } if(r+1 < n && l-1 >= 0 && map[r+1][l-1] == '*') { count++; } if(r+1 < n && map[r+1][l] == '*') { count++; } if(r+1 < n && l+1 < n && map[r+1][l+1] == '*') { count++; } if(l+1 < n && map[r][l+1] == '*') { count++; } if(r-1 >= 0 && l+1 < n && map[r-1][l+1] == '*') { count++; } return count;}
- ZOJ-1862 Mine Sweeper
- POJ 2612/ZOJ 1862 Mine Sweeper
- Mine Sweeper
- Mine Sweeper
- fjnu 1579 Mine Sweeper
- 1006: Mine Sweeper(扫雷)
- Mine Sweeper 水题
- poj 2612 Mine Sweeper
- poj 2612 Mine Sweeper
- TOJ : 1330. Mine Sweeper
- poj 2612 Mine Sweeper
- poj 2612 Mine Sweeper
- UVa 10279 - Mine Sweeper
- POJ 2612 Mine Sweeper 模拟
- POJ 2612 Mine Sweeper G++
- 模拟->YY POJ 2612 Mine Sweeper
- POJ 2612 Mine Sweeper 扫雷游戏
- POJ 2612 Mine Sweeper(水~)
- 快排模板
- GE如何测试大型客机引擎
- 修改SQLServer2008express的sa帐号密码
- c语言双向链表的实现
- 【OpenGL】OpenGL绘图的一点理解
- ZOJ-1862 Mine Sweeper
- 最短路径简单应用 畅通工程续 POJ 1874
- LeetCode: Combination Sum
- c语言一个栈的实现
- 可重入函数和不可重入函数
- JAVA不支持C++的模板
- new
- c语言队列的实现
- java.io.tmpdir的默认在操作系统的什么位置以及如何配置