Mine Sweeper
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6429   Accepted: 2500

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. 

 

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. 

Input

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.

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...

注意:假设踩到地雷。要把全部地雷表示出来。

#include <iostream>
using 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<n)
ans++; if (map[i][j-1]=='*' && j-1>=0)
ans++;
if (map[i][j]=='*')
ans++;
if (map[i][j+1]=='*' && j+1<n)
ans++; if (map[i+1][j-1]=='*' && i+1<n && j-1>=0)
ans++;
if (map[i+1][j]=='*' && i+1<n)
ans++;
if (map[i+1][j+1]=='*' && i+1<n && j+1<n)
ans++;
return ans;
}
int main(){ while (cin>>n){
for (int i=0;i<n;i++)
for (int j=0;j<n;j++)
cin>>map[i][j];
int flag=0;
for (int i=0;i<n;i++){
for (int j=0;j<n;j++){
cin>>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<n;i++){
for (int j=0;j<n;j++){
if (flag==1 && map[i][j]=='*')
cout<<map[i][j];
else
cout<<ans[i][j];
}
cout<<endl;
}
}
return 0;
}

poj 2612 Mine Sweeper的更多相关文章

  1. 2020杭电多校 10C / HDU 6879 - Mine Sweeper (构造)

    HDU 6879 - Mine Sweeper 题意 定义<扫雷>游戏的地图中每个空白格子的值为其周围八个格子内地雷的数量(即游戏内临近地雷数量的提示) 则一张地图的值\(S\)为所有空白 ...

  2. POJ 2612

    #include<iostream> #include<stdio.h> #include<algorithm> #define MAXN 11 using nam ...

  3. 2020杭电多校 C / HDU 6879 - Mine Sweeper

    题意: t组输入,每组输入一个s 你需要输出一个r行c列的阵列,这个阵列中'X'代表炸弹,'.'表示没有炸弹 对于'.'这些位置都会有一个数值,这个值取决于这个位置附近8个位置,这8个位置一共有几个炸 ...

  4. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  5. 多级弹出菜单jQuery插件ZoneMenu

    ZoneMenu是一个菜单jQuery插件,只需占用页面上的一个小区域,却可以实现多级菜单. 在线体验:http://keleyi.com/jq/zonemenu/ 点击这里下载 完整HTML文件代码 ...

  6. 中英文代码对比系列之Java一例

    原文: https://zhuanlan.zhihu.com/p/30905033. 作者为本人. 这个系列将对同一段代码进行中文命名和英文命名两个版本的比较. 目的包括, 演示中文命名, 发现命名时 ...

  7. 2017-11-09 中英文代码对比系列之Java一例

    原文: https://zhuanlan.zhihu.com/p/30905033. 作者为本人. 这个系列将对同一段代码进行中文命名和英文命名两个版本的比较. 目的包括, 演示中文命名, 发现命名时 ...

  8. FZU1920 Left Mouse Button(dfs)

     Problem 1920 Left Mouse Button Accept: 385    Submit: 719 Time Limit: 1000 mSec    Memory Limit : 3 ...

  9. [转]分享20佳好玩的 jQuery 游戏

    本文转自:http://www.cnblogs.com/lhb25/archive/2011/04/17/2001089.html jQuery是时下最流行的 JavaScript 库.现在,除了HT ...

随机推荐

  1. Spork: Pig on Spark实现分析

    介绍 Spork是Pig on Spark的highly experimental版本号,依赖的版本号也比較久,如之前文章里所说.眼下我把Spork维护在自己的github上:flare-spork. ...

  2. java.io.IOException: Cannot find any registered HttpDestinationFactory from the Bus.

    转自:https://blog.csdn.net/u012849872/article/details/51037374

  3. ThinkPHP5+Redis单例型购物车

    <?php /** * Redis + 单例型购物车 * param $basket 存储商品信息 * param $ins 存储实例化对象 */ namespace lib; use redi ...

  4. GCD的小结

    同步和异步的区别 同步:在当前线程中执行 异步:在另一条线程中执行 有4个术语比较容易混淆:同步.异步.并发.串行 同步和异步决定了要不要开启新的线程 同步:在当前线程中执行任务,不具备开启新线程的能 ...

  5. Redis学习笔记(六) 基本命令:List操作

    原文链接:http://doc.redisfans.com/list/index.html lpush key value[value...] 将一个或多个value插入到列表的表头:例:lpush ...

  6. ElementUI 表格表头筛选框的高度设置,超出一定高度,显示滚动条

    最近项目发现一个问题table表头筛选的时候,由于筛选内容过多导致弹出框超出屏幕,并且无法滚动,应急的办法是缩小浏览器显示比例让更多内容显示

  7. windows下安装reidis

    下载windows下redis安装包 https://github.com/MSOpenTech/redis/releases 这时候另启一个cmd窗口,原来的不要关闭,不然就无法访问服务端了. 切换 ...

  8. 修改WebAPI路由控制访问

    1.方式一:修改RouteConfig.cs文件 2.方式二:通过在方法上方添加[Route("api/XXXX")]来控制

  9. DOM基础知识(Node对象、Element对象)

    5.Node对象 u  遍历节点 u 父节点 .parentNode - 获取父节点—> 元素节点或文档节点 .parentElement - 获取父元素节点—> 元素节点 u    子节 ...

  10. hiho 1476 - 矩形计数 容斥

    题目链接 如图所示,在由N行M列个单位正方形组成的矩形中,有K个单位正方形是黑色的,其余单位正方形是白色的. 你能统计出一共有多少个不同的子矩形是完全由白色单位正方形组成的吗? ----------- ...