烟大 Contest1024 - 《挑战编程》第一章:入门 Problem B: Minesweeper(模拟扫雷)
Problem B: Minesweeper
Time Limit: 1 Sec Memory Limit: 64 MB
Submit: 29 Solved: 7
[Submit][Status][Web Board]
Description
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
Input
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<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.
Output
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.
Sample Input
Sample Output
HINT
模拟题。模拟的是扫雷这个小游戏。输入雷的分布,输出每一个格子四周的雷数矩阵。也就是模拟扫雷里数字的产生过程。
一开始把计算那一步想的复杂了,由于没有初始化,我只好把检测的情况分为边缘、内部,边缘又分为四角和边,这样有三种情况,每一种情况的检测区域又不一样,我要每一种都分别定义。后来发现没必要分类,直接检测周围8个格子的区域就行,只不过这样就需要提前初始化好以及让数组留出边缘。
My code:
- #include <iostream>
- using namespace std;
- int main()
- {
- char a[][]={};
- int n,m,count=;
- while(cin>>n>>m){
- if(n== && m==)
- break;
- for(int i=;i<=n;i++) //input
- for(int j=;j<=m;j++)
- cin>>a[i][j];
- for(int i=;i<=n;i++) //计算
- for(int j=;j<=m;j++){
- if(a[i][j]=='*')
- continue;
- a[i][j]='';
- if(a[i-][j]=='*')
- ++a[i][j];
- if(a[i+][j]=='*')
- ++a[i][j];
- if(a[i][j+]=='*')
- ++a[i][j];
- if(a[i][j-]=='*')
- ++a[i][j];
- if(a[i-][j-]=='*')
- ++a[i][j];
- if(a[i-][j+]=='*')
- ++a[i][j];
- if(a[i+][j-]=='*')
- ++a[i][j];
- if(a[i+][j+]=='*')
- ++a[i][j];
- }
- if(count!=)
- cout<<endl;
- cout<<"Field #"<<count++<<':'<<endl;
- for(int i=;i<=n;i++){ //输出
- for(int j=;j<=m;j++){
- cout<<a[i][j];
- }
- cout<<endl;
- }
- }
- return ;
- }
- /**************************************************************
- Problem: 1099
- User: freecode
- Language: C++
- Result: Accepted
- Time:0 ms
- Memory:1268 kb
- ****************************************************************/
Freecode : www.cnblogs.com/yym2013
烟大 Contest1024 - 《挑战编程》第一章:入门 Problem B: Minesweeper(模拟扫雷)的更多相关文章
- ACM YTU 《挑战编程》第一章 入门 Problem E: Graphical Editor
Description Graphical editors such as Photoshop allow us to alter bit-mapped images in the same way ...
- Windows核心编程第一章.错误处理
Windows核心编程第一章,错误处理. 一丶错误处理 1.核心编程学习总结 不管是做逆向,开始做开发.在Windows下.你都需要看一下核心编程这本书.这本书确实写得很好.所以自己在学习这本书的同时 ...
- .NET Core实战项目之CMS 第一章 入门篇-开篇及总体规划
作者:依乐祝 原文地址:https://www.cnblogs.com/yilezhu/p/9977862.html 写在前面 千呼万唤始出来,首先,请允许我长吸一口气!真没想到一份来自28岁老程序员 ...
- net core体系-web应用程序-4asp.net core2.0 项目实战(CMS)-第一章 入门篇-开篇及总体规划
.NET Core实战项目之CMS 第一章 入门篇-开篇及总体规划 原文地址:https://www.cnblogs.com/yilezhu/p/9977862.html 写在前面 千呼万唤始出来 ...
- Java 面向对象编程——第一章 初识Java
第一章 初识Java 1. 什么是Java? Java是一种简单的.面向对象的.分布式的.解释的.安全的.可移植的.性能优异的多线程语言.它以其强安全性.平台无关性.硬件结构无关性.语言简 ...
- Java学习笔记 第一章 入门<转>
第一章 JAVA入门 一.基础常识 1.软件开发 什么是软件? 软件:一系列按照特定顺序组织的计算机数据和指令的集合 系统软件:DOS,Windows,Linux 应用软件:扫雷.QQ.迅雷 什么是开 ...
- windows核心编程-第一章 对程序错误的处理
第一章-对程序错误的处理 在开始介绍Microsoft Windows 的特性之前,必须首先了解 Wi n d o w s的各个函数是如何进行错误处理的. 当调用一个Wi n d o w s函数时,它 ...
- UNIX环境高级编程--第一章 UNIX基础知识
第一章 UNIX基础知识 1.2 UNIX体系结构 从严格意义上说,可将操作系统定义为一种软件,它控制计算机硬件资源,提供程序运行环境.我们将这种软件称为内核(kernel),因为 它相对较小,且 ...
- 读高性能JavaScript编程 第一章
草草的看完第一章,虽然看的是译文也是感觉涨姿势了, 我来总结一下: 由于 大多数浏览器都是 single process 处理 ui updatas and js execute 于是产生问题: js ...
- Go Web 编程 第一章 Web相关概念
第一章 Go与Web应用 Go学习群:415660935 1.1 Web应用 在计算机的世界里,应用(application)是一个与用户进行交互,并完成用户特定任务的软件程序.而Web应用则是部署在 ...
随机推荐
- hdu 2047 阿牛的EOF牛肉串
如果末尾加的是E或F,显然是2*a[i-1] 如果末尾加的是O,则末2位一定是EO或FO,则为2*a[i-2]. 然后两者相加 2*a[i-1]+2*a[i-2] = 2*(a[i-1]+a[i-2] ...
- hdu 2046 骨牌铺方格
#include<stdio.h> int main(void) { long long i,n,narr[55]; narr[1]=1;narr[2]=2;narr[3]=3; for( ...
- hdu 2050 折线分割平面
训练递推用题,第一次做这个题,蒙的,而且对了. #include <stdio.h> int main(void) { int c,a; scanf("%d",& ...
- hibernate的pojo和xml文件
- sqlplus 配置方法及相关命令
sqlplus 配置方法及相关命令 1.配置文件 1.1 全局模式什么叫全局模式呢:当我们配置完sqlplus工具加载配置文件后,无论在哪个目录下登陆数据库,您设置[sqlplus提示符样子,在任何目 ...
- php的urlencode()URL编码函数浅析
URLEncode:是指针对网页url中的中文字符的一种编码转化方式,最常见的就是Baidu.Google等搜索引擎中输入中文查询时候,生成经过Encode过的网页URL. URLEncode的方 ...
- Intent的Flag
小段代码: Intent it=new Intent(); it.setClass(Setting.this,Main.class);//从Setting跳转到Main it.addFlags(Int ...
- 服务器部署之 cap deploy:setup
文章是从我的个人博客上粘贴过来的, 大家也可以访问 www.iwangzheng.com $ cap deploy:setup 执行到这一步的时候会时间较长,可以直接中断 * executing &q ...
- PHPStorm+Wamp+Xdebug+Windows7调试代码
Wamp 集成环境 PHPStorm+Xdebug 调试代码 2013.04.16 花了两个小时时间终于 , 配置成功了 ! 我的开发环境如下 , 其它环境也可以参考我的配置 开发环境 : Windo ...
- 【系统】CentOS、Ubuntu、Debian三个linux比较异同
CentOS.Ubuntu.Debian三个linux比较异同 2014-07-31 12:58 53428人阅读 评论(6) ...