你玩过扫雷吗?这个可爱的小游戏带有一个我们记不住名字的操作系统。游戏的目标是找到所有地雷在M x N场中的位置。游戏在一个正方形中显示一个数字,它告诉你在这个正方形附近有
多少个地雷。每个方块最多有八个相邻方块。左侧的4x 4字段包含两个地雷,每个地雷由一个“`*”字符表示。如果我们用上面描述的提示数来表示同一个字段,
我们最后得到右边的字段:*……*…*100 2210 1*10 1110
输入将由任意数量的字段组成。每个字段的第一行包含两个整数n和m(0<n,m$\le$100),分别代表字段的行数和列数。接下来的n行中的每一行正好包含m个字符,表示字段。安全方格
用`.'表示,矿山方格用`.*表示,两者都没有引号。n=m=0的第一行字段表示输入结束,不应进行处理。
For each field, print the message Field #x: on a line alone, where x stands for the number of the field starting from 1. The next n lines
should contain the field withthe ``.'' characters replaced by the number of mines adjacent to that square. There must be an empty line
between field outputs.
对于每个字段,单独在一行上打印消息字段x,其中x代表从1开始的字段编号。接下来的n行应该包含带有“..”字符的字段,替换为该广场附近的地雷数量。字段输出之间必须有空行。
//扫雷游戏
#include<iostream>
#include<cstring>
using namespace std;
int i,j;
char g[][];
int book[][];
int gcd(int x,int y){
int num=;
if(g[x][y]=='*') return -;
// cout<<"hello"<<endl;
for(int xx=x-;xx<=x+;xx++){
for(int yy=y-;yy<=y+;yy++){ if(xx==x&&yy==y) continue;
if(g[xx][yy]=='*') num++;
}
}
return num;
}
int main()
{
memset(book,,sizeof(book));
memset(g,,sizeof(g)); int m,n;
int num=;
while(cin>>m>>n&&m&&n){
num++;
memset(book,,sizeof(book));
memset(g,,sizeof(g));
for(i=;i<=m;i++){
for(j=;j<=n;j++)
cin>>g[i][j];
}
for(i=;i<=m;i++){
for(j=;j<=n;j++){
book[i][j]=gcd(i,j);
} }
printf("Field #%d:\n",num);
for(i=;i<=m;i++){
for(j=;j<=n;j++){
if(book[i][j]!=-) cout<<book[i][j];
else cout<<"*";
// cout<<book[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
}
}

广度优先搜索就行

主要问题是害怕看英文,多看看英语阅读

题目描述
Minesweeper Have you ever played Minesweeper? This cute little game comes with a certain
operating system whose name we can't remember. The goal of the game is to find where all
the mines are located within a M x N field. The game shows a number in a square which tells
you how many mines there are adjacent to that square. Each square has at most eight
adjacent squares. The 4 x 4 field on the left contains two mines, each represented by a ``*''
character. If we represent the same field by the hint numbers described above, we end up with
the field on the right: *... .... .*.. .... *100 2210 1*10 1110
输入
The input will consist of an arbitrary number of fields. The first line of each field contains two
integers n and m ( 0 < n, m$ \le$100) which stand for the number of lines and columns of the
field, respectively. Each of the next n lines contains exactly m characters, representing the field. Safe squares are denoted by ``.'' and mine squares by ``*,'' both without the quotes. The first field line where n = m = 0 represents the end of input and should not be processed.
输出
For each field, print the message Field #x: on a line alone, where x stands for the number of the field starting from 1. The next n lines should contain the field with the ``.'' characters replaced by the number of mines adjacent to that square. There must be an empty line between field outputs.
样例输入
4 4
*...
....
.*..
....
3 5
**...
.....
.*...
0 0
样例输出
Field #1:
*100
2210
1*10
1110 Field #2:
**100
33200
1*100

  

 

Minesweeper的更多相关文章

  1. 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem B: Minesweeper(模拟扫雷)

    Problem B: Minesweeper Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 29  Solved: 7[Submit][Status][W ...

  2. [LeetCode] Minesweeper 扫雷游戏

    Let's play the minesweeper game (Wikipedia, online game)! You are given a 2D char matrix representin ...

  3. [Swift]LeetCode529. 扫雷游戏 | Minesweeper

    Let's play the minesweeper game (Wikipedia, online game)! You are given a 2D char matrix representin ...

  4. 529. Minesweeper扫雷游戏

    [抄题]: Let's play the minesweeper game (Wikipedia, online game)! You are given a 2D char matrix repre ...

  5. LeetCode 529. Minesweeper

    原题链接在这里:https://leetcode.com/problems/minesweeper/description/ 题目: Let's play the minesweeper game ( ...

  6. leetcode笔记(七)529. Minesweeper

    题目描述 Let's play the minesweeper game (Wikipedia, online game)! You are given a 2D char matrix repres ...

  7. Google Code Jam 2014 资格赛:Problem C. Minesweeper Master

    Problem Minesweeper is a computer game that became popular in the 1980s, and is still included in so ...

  8. 529 Minesweeper 扫雷游戏

    详见:https://leetcode.com/problems/minesweeper/description/ C++: class Solution { public: vector<ve ...

  9. YTU 1099: Minesweeper

    1099: Minesweeper 时间限制: 1 Sec  内存限制: 64 MB 提交: 180  解决: 98 题目描述 Minesweeper Have you ever played Min ...

随机推荐

  1. Visual Studio语言设置

    按照的是中文的visual studio,用起来很不方便,因为程序员的都是英文版,平时交流时也是英文的名字 转换语言时发现只有中文和跟随windows系统的设置 官方给的文档看的不是很清楚 查阅资料后 ...

  2. C#发布和调试WebService

    一.编写并发布WebService服务 1.新建空web应用程序

  3. c/c++ 通用的(泛型)算法 之 只读算法,写算法,排序算法

    通用的(泛型)算法 之 只读算法,写算法,排序算法 只读算法: 函数名 功能描述 accumulate 求容器里元素的和 equal 比较2个容器里的元素 写算法 函数名 功能描述 fill 用给定值 ...

  4. c/c++线性队列

    线性队列 队列是先进先出,和栈相反. 不循环的队列就是浪费空间,如果tail到了最大值后,即使前面出队了,有空的位置,也不能再入队. seqqueue.h #ifndef __SEQQUEUE__ # ...

  5. 如何阅读luajit的代码——用vs调试篇

    为什么要看luajit的源码 作为目前最快的脚本语言之一,luajit确实是一个杰作,但相比原生lua仅仅几万行的代码而言,luajit却可以说是巨无霸.更要命的是,luajit之所以快,是因为大量使 ...

  6. Windows 快捷方式(*.link)打开方式关联错误

    1.Win+r 组合键打开 “运行”,输入 “regedit” 打开 注册表 2.依次打开注册表,定位到以下位置: HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\WINDO ...

  7. 【2018.08.13 C与C++基础】网络通信:阻塞与非阻塞socket的基本概念及简单实现

    一.前言 最近在做Matalb/Simulink与C/C++的混合编程,主要是完成TCP.UDP.SerialPort等常见通信方式的中间件设计,为Simulink模型提供数据采集及解析模块. 问题在 ...

  8. 删除排序链表中的重复元素的golang实现

    给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次. 输入: ->-> 输出: -> 输入: ->->->-> 输出: ->-> 我们先 ...

  9. CF 1110 D/E

    CF 1110 D. Jongmah 题目大意:给你​\(n\)个瓷砖,每块瓷砖上有一个数字​\(a_i,(1\leq a_i\leq m)\).你可以将三个有连续数字​\((比如3,4,5)\)的瓷 ...

  10. go 调用windows dll 的三种方法

    参考:https://blog.csdn.net/qq_39584315/article/details/81287669 大部分代码参考:https://studygolang.com/articl ...