你玩过扫雷吗?这个可爱的小游戏带有一个我们记不住名字的操作系统。游戏的目标是找到所有地雷在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. Zabbix监控文件是否存在/文件大小

    检查C:\Zabbix\zabbix_agentd.log文件是否存在 zabbix_get -s 10.16.4.1 -k vfs.file.exists[C:\\Zabbix\\zabbix_ag ...

  2. rabbitMQ模式

    1.hello  消息生产者p将消息放入队列 消费者监听队列,如果队列中有消息,就消费掉,消息被拿走后,自动从队列删除(隐患,消息可能没有被消费者正确处理,已经消失了,无法恢复) 应用场景:聊天室 案 ...

  3. 4.10Python数据处理篇之Matplotlib系列(十)---文本的显示

    目录 目录 前言 (一)中文显示 ==1.全局的设置== ==2.局部的设置== (二)文本显示 目录 前言 今天我们来学习一下文本的显示 (一)中文显示 ==1.全局的设置== (1)说明: 在ma ...

  4. LeetCode算法题-Pascal's Triangle(Java实现)

    这是悦乐书的第170次更新,第172篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第29题(顺位题号是118).给定非负整数numRows,生成Pascal三角形的第一个 ...

  5. 类中的 this关键字

    this可用于区分局部变量和成员变量,因为构造函数中如果使用 this.成员变量 = 参数值, 那么可以在new对象时,将初始化值赋值给成员变量,否则成员变量赋值失败, 所以this可以区分成员变量和 ...

  6. leetcode刷题--两数之和(简单)

    一.序言 第一次刷leetcode的题,之前从来没有刷题然后去面试的概念,直到临近秋招,或许是秋招结束的时候才有这个意识,原来面试是需要刷题的,面试问的问题都是千篇一律的,只要刷够了题就差不多了,当然 ...

  7. Sudoku 小项目

    Sudoku 小项目 - 软工第二次作业 Part 1 · 项目相关 Github 地址: https://github.com/TheSkyFucker/Sudoku 项目的更多信息以及所有开发文档 ...

  8. .net 解决伪静态下,html页面无法访问

    1.在<system.web>节点下添加: <!--URL重写文件设置开始--> <httpHandlers> <add verb="*" ...

  9. nginx相关命令

    https://www.cnblogs.com/zdz8207/p/CentOS-nginx-yum.html

  10. 7.01-beautiful_soup3

    # pip install beautifulsoup4 from bs4 import BeautifulSoup html_doc = """ <html> ...