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

4 4
*...
....
.*..
....
3 5
**...
.....
.*...
0 0

Sample Output

Field #1:
*100
2210
1*10
1110
 
 
Field #2:
**100
33200
1*100

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(模拟扫雷)的更多相关文章

  1. ACM YTU 《挑战编程》第一章 入门 Problem E: Graphical Editor

    Description Graphical editors such as Photoshop allow us to alter bit-mapped images in the same way ...

  2. Windows核心编程第一章.错误处理

    Windows核心编程第一章,错误处理. 一丶错误处理 1.核心编程学习总结 不管是做逆向,开始做开发.在Windows下.你都需要看一下核心编程这本书.这本书确实写得很好.所以自己在学习这本书的同时 ...

  3. .NET Core实战项目之CMS 第一章 入门篇-开篇及总体规划

    作者:依乐祝 原文地址:https://www.cnblogs.com/yilezhu/p/9977862.html 写在前面 千呼万唤始出来,首先,请允许我长吸一口气!真没想到一份来自28岁老程序员 ...

  4. net core体系-web应用程序-4asp.net core2.0 项目实战(CMS)-第一章 入门篇-开篇及总体规划

    .NET Core实战项目之CMS 第一章 入门篇-开篇及总体规划   原文地址:https://www.cnblogs.com/yilezhu/p/9977862.html 写在前面 千呼万唤始出来 ...

  5. Java 面向对象编程——第一章 初识Java

      第一章    初识Java 1.  什么是Java? Java是一种简单的.面向对象的.分布式的.解释的.安全的.可移植的.性能优异的多线程语言.它以其强安全性.平台无关性.硬件结构无关性.语言简 ...

  6. Java学习笔记 第一章 入门<转>

    第一章 JAVA入门 一.基础常识 1.软件开发 什么是软件? 软件:一系列按照特定顺序组织的计算机数据和指令的集合 系统软件:DOS,Windows,Linux 应用软件:扫雷.QQ.迅雷 什么是开 ...

  7. windows核心编程-第一章 对程序错误的处理

    第一章-对程序错误的处理 在开始介绍Microsoft Windows 的特性之前,必须首先了解 Wi n d o w s的各个函数是如何进行错误处理的. 当调用一个Wi n d o w s函数时,它 ...

  8. UNIX环境高级编程--第一章 UNIX基础知识

    第一章 UNIX基础知识 1.2 UNIX体系结构   从严格意义上说,可将操作系统定义为一种软件,它控制计算机硬件资源,提供程序运行环境.我们将这种软件称为内核(kernel),因为 它相对较小,且 ...

  9. 读高性能JavaScript编程 第一章

    草草的看完第一章,虽然看的是译文也是感觉涨姿势了, 我来总结一下: 由于 大多数浏览器都是 single process 处理 ui updatas and js execute 于是产生问题: js ...

  10. Go Web 编程 第一章 Web相关概念

    第一章 Go与Web应用 Go学习群:415660935 1.1 Web应用 在计算机的世界里,应用(application)是一个与用户进行交互,并完成用户特定任务的软件程序.而Web应用则是部署在 ...

随机推荐

  1. cannot get gid for group ‘nobody’

    启动php-fpm /data1/server/php-cgi/sbin/php-fpm 错误[28-Mar-2012 11:15:01] ERROR: failed to open configur ...

  2. Android SDK Manager和AVD Manager使用

    Android SDK Manager和AVD Manager使用(win7_64bit下测试) 目录 1.概述 2.本文用到的工具 3.安卓开发基础工具包下载 4.Android SDK Manag ...

  3. Visual Studio Online Integrations-Sync and migration

      原文:http://www.visualstudio.com/zh-cn/explore/vso-integrations-directory-vs

  4. ubuntu下手把手教你搭建SVN服务器

    序,我的ubuntu服务器版本是14.04 ,x64(64位)操作系统,服务器在国内. 目录 一.安装SVN服务器 1 安装svn2 创建目录3 创建版本仓库4 配置5 启动SVN服务器6 验证svn ...

  5. centos linux从无到有安装wordpress

    序:本博客从无到有搭建wordpress,包括从服务器和域名购买,会将步骤一步一步记录下来.如果你也是新手,那你有福了,因为我的系统是centos,对号入座啊. 目录 一.准备域名和服务器一.安装ph ...

  6. SQL例题合集

    1. 查询Student表中的所有记录的Sname.Ssex和Class列. Select sname,ssex,class from student; 2. 查询教师所有的单位即不重复的Depart ...

  7. Tautology(structure)

    Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10061   Accepted: 3826 Descri ...

  8. [Effective JavaScript 笔记] 第13条:使用立即调用的函数表达式创建局部作用域

    function wrapElements(a){ var res=[],i,n; for(i=0,n=a.length;i<n;i++){ res[i]=function(){return a ...

  9. easyui-datagrid 两次请求

    原因分析及解决方案 html代码中利用class声明了datagrid,导致easyUI解析class代码的时候先解析class声明中的datagrid,这样组件就请求了一次url:然后又调用js初始 ...

  10. squid日志配置与轮询

    squid日志分类及参数 SQUID默认的log文件非常多,其中最重要的LOG日志有三个,分别为access.log.store.log.cache.log.三个日志的记录的内容如下: access. ...