描述:

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.

Here, n is 8, m is 10, blank squares represent the integer 0, raised squares represent unplayed positions, and the figures resembling asterisks represent mines. The leftmost image 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. From the second image to the third, the player is not so lucky; he chooses a position with a mine and therefore loses. The player wins if he continues to make safe moves until only m unplayed positions remain; these must necessarily contain the mines.

Your job is to read the information for a partially played game and to print the corresponding board.

输入:

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


输出:

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.

样例输入:

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

样例输出:

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

题目大意:

输入一个正整数n接下去n行是n*n的地图*表示地雷位置,接下去n行n列为地图的位置如果为x表示为探索过的位置。如果探索过的位置为*则输出地图中所有雷的位置,如果为.输出周围的雷的数量。

代码如下:

#include<stdio.h>
int n;
char map[15][15],map1[15][15];
int find(int a,int b)                       //搜索map[a][b]周围的地雷数量
{int e=0;for(int x=-1;x<=1;x++){for(int y=-1;y<=1;y++){if(x==0&&y==0)continue;else{if(x+a>=0&&x+a<n&&y+b>=0&&y+b<n&&map[x+a][y+b]=='*')e++;}}}return e;
}
void print()
{for(int i=0;i<n;i++){for(int j=0;j<n;j++){printf("%c",map1[i][j]);}printf("\n");}
}
void sove()                                 //打印所有雷的位置
{for(int i=0;i<n;i++){for(int j=0;j<n;j++){if(map[i][j]=='*'){map1[i][j]='*';}}}
}
int main()
{scanf("%d",&n);for(int i=0;i<n;i++){scanf("%s",map[i]);}for(int i=0;i<n;i++){scanf("%s",map1[i]);}   for(int i=0;i<n;i++){for(int j=0;j<n;j++){if(map1[i][j]=='x'&&map[i][j]!='*'){int count=find(i,j);map1[i][j]=count+'0';}if(map1[i][j]=='x'&&map[i][j]=='*')              {sove();}          }}print();return 0;
}

Mine Sweeper相关推荐

  1. Mine Sweeper II

    Mine Sweeper II 题意: 给你两个大小为 n * m 的扫雷图 A, B,要求通过最多 n * m/2 次转换(转换指 把一个不是雷的格子变成雷, 或者把一个是雷的格子变成空白格),使得 ...

  2. 构造 - Mine Sweeper II - ICPC 2020 上海

    构造 - Mine Sweeper II - ICPC 2020 上海 题意: 给 定 两 个 n × m 的 由 ′ X ′ 和 ′ . ′ 矩 阵 A 和 B , 表 示 两 个 扫 雷 的 矩 ...

  3. 2020 icpc上海站 Mine Sweeper II

    Mine Sweeper II 题意 给你两个用"."和X组成的矩阵,X表示地雷,每个"."周围八个格子有几个雷贡献就是多少,改变第二个字符矩阵,使最后两个矩阵 ...

  4. gym 102900 Mine Sweeper II

    gym 102900 Mine Sweeper II 题目链接 题意 给定两个 n × m n\times m n×m的扫雷地图 A , B A,B A,B,所有非地雷格子都有一个数字,表示这个格子周 ...

  5. POJ 2612 Mine Sweeper 扫雷游戏

    原题 http://poj.org/problem?id=2612 题目: Mine Sweeper Time Limit: 1000MS Memory Limit: 65536K Total Sub ...

  6. 上海ICPC Mine Sweeper II

    上海ICPC Mine Sweeper II 题意:给定扫雷图 A A A和 B B B,它们的大小为 n × m n\times m n×m,设 A A A中所有空白格的贡献为 s u m sum ...

  7. [C语言]扫雷游戏(Mine Sweeper)

    目录 扫雷游戏:: game.h game.c 1.打印菜单 2.初始化雷区 3.打印雷区 4.布置雷 5.排查雷 6.统计排查坐标周围雷的个数 test.c 扫雷游戏:: game.h #pragm ...

  8. 2020ICPC上海 B Mine Sweeper II(思维)

    链接 题目描述 A mine-sweeper map X {X} X can be expressed as an n × m n\times m n×m grid. Each cell of the ...

  9. 搜索04 Mine Sweeper

    题目链接 Description The game Minesweeper is played on an n by n grid. In this grid are hidden m mines, ...

最新文章

  1. 一般筛法求素数+快速线性筛法求素数
  2. PCA(Principal Component Analysis)的原理、算法步骤和实现。
  3. js 拖动层示例[转]
  4. 裸奔浏览器_大概是最好用的隐私浏览器 - Firefox Focus
  5. 聊聊spring cloud的DefaultEurekaServerContext
  6. 从Theano到Lasagne:基于Python的深度学习的框架和库
  7. Python中关于‘self’的种种用法笔记
  8. Android之解决Gigaset手机不能设置DeviceOwner权限提示already provisioned问题
  9. 微基准测试进入Java 9
  10. boost锁机制中Semaphores的介绍
  11. 原来真的不会用指针[*p++]
  12. oracle 10g ocp 047解析(精简版),Oracle 10g OCP题库解析(042、043、047)(转载)
  13. 阿里 卫哲谈阿里人力招聘价值观
  14. MBP远程控制Windows NUC
  15. 穿上钢铁侠战衣变身钢铁侠,现代表示我做到了!
  16. 微信小程序苹果IOS手机无法加载显示临时图片路径
  17. multisim中pwl_开关在multisim中怎么找
  18. matlab中za是什么意思,大学统计学 计算Za/2的时候 什么情况下直接取样本n 什么情况是要计算df=n-1的...
  19. 在python中用sql创建表_Python Pandas to_sql,如何用主键创建表?
  20. java 内存压缩_JVM之指针压缩内存如何设置

热门文章

  1. 答辩要点和答辩常见问题及作答
  2. 第十一章——电子商务网站用户行为分析及服务推荐
  3. 时尚与品牌(网络选修通识课)
  4. 题解 CF103A 【Testing Pants for Sadness】
  5. 如何调节沃福激光器的最低输出功率
  6. JDK环境变量配置以及可能出现的乱码问题
  7. idea 的反撤销快捷键失效解决方案
  8. 创建型设计模式----工厂方法模式
  9. easyExcel 填写导出转换日期格式
  10. oracle trim函数用法详解,oracle trim函数用法详解