1099: Minesweeper

时间限制: 1 Sec  内存限制: 64 MB

提交: 180  解决: 98

题目描述

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<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
#include <stdio.h>
#include <string.h>
int main()
{
char lei[120][120];
int ci=0,n,m;
while(~scanf("%d%d",&n,&m)&&(n||m))
{
memset(lei,'0',sizeof(lei));
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++)
{
char x;
scanf(" %c",&x);
if(x=='*')
{
lei[i][j]='*';
for(int ii=i-1; ii<=i+1; ii++)
for(int jj=j-1; jj<=j+1; jj++)
if(lei[ii][jj]!='*')lei[ii][jj]++;
}
}
printf("Field #%d:\n",++ci);
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++)printf(j!=m?"%c":"%c\n",lei[i][j]);
printf("\n");
}
return 0;
}

总是望着曾经的空间发呆,那些说好不分开的朋友不在了,转身,陌路。 熟悉的,安静了, 安静的,离开了, 离开的,陌生了, 陌生的,消失了, 消失的,陌路了。

YTU 1099: Minesweeper的更多相关文章

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

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

  2. ytu 1057: 输入两个整数,求他们相除的余数(带参的宏 + 模板函数 练习)

    1057: 输入两个整数,求他们相除的余数 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 177  Solved: 136[Submit][Status ...

  3. 启动tomcat时 错误: 代理抛出异常 : java.rmi.server.ExportException: Port already in use: 1099;

     错误: 代理抛出异常 : java.rmi.server.ExportException: Port already in use: 1099; nested exception is:  java ...

  4. poj 1099

    http://poj.org/problem?id=1099 #include<stdio.h> #include<string.h> #include <iostrea ...

  5. 启动tomcat时 错误: 代理抛出异常 : java.rmi.server.ExportException: Port already in use: 1099的解决办法

    一.问题描述 今天一来公司,在IntelliJ IDEA 中启动Tomcat服务器时就出现了如下图所示的错误:

  6. ytu 1058: 三角形面积(带参的宏 练习)

    1058: 三角形面积 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 190  Solved: 128[Submit][Status][Web Boar ...

  7. idea启动tomcat失败,1099端口被占用

    今天遇到一个问题,当使用idea启动一个tomat服务的时候,报错:不能连接本地1099端口. /Users/liqiu/soft/develop/apache-tomcat-/bin/catalin ...

  8. ACdream OJ 1099 瑶瑶的第K大 --分治+IO优化

    这题其实就是一个求数组中第K大数的问题,用快速排序的思想可以解决.结果一路超时..原来要加输入输出优化,具体优化见代码. 顺便把求数组中第K大数和求数组中第K小数的求法给出来. 代码: /* * th ...

  9. ytu 1980:小鼠迷宫问题(DFS 深度优先搜索)

     小鼠迷宫问题 Time Limit: 2 Sec  Memory Limit: 64 MB Submit: 1  Solved: 1 [Submit][Status][Web Board] Desc ...

随机推荐

  1. [SHELL]awk的用法举例

    从初学awk到现在小有所成,非常感谢CUers的帮助,总结了下自己曾经遇到的问题和犯的错误,供初学者借鉴,因本人非计算机专业,对专业词汇可能有表述不对的地方,还请指正和补充! 1. awk '{cod ...

  2. 【Codeforces 1006D】Two Strings Swaps

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 注意只能改变a不能改变b 然后只要让a[i],b[i],a[n-i-1],b[n-i-1]这4个字符能凑成两对.全都一样就可以了 分类讨论下就 ...

  3. linux awk常用命令【转载】

    简介 awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大.简单来说awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分再 ...

  4. A. Link/Cut Tree--cf614A ()

    这个题卡精度了  刚开始是2的57次方都已经有误差了  不知道怎么弄 后来加个求余就好了 #include<stdio.h> #include<math.h> #include ...

  5. MAC地址泛红攻击

    一.环境 IP地址: Windows10   IP:10.13.153.55 Windows7:   IP:192.168.83.130 Linux:       IP:192.168.83.129 ...

  6. grunt安装,配置记录

    进了新的公司,需要重构一个项目,从头开始.本人患懒癌已久,一直没有写博客的打算,也是因为资质还比较浅,写不出什么富有涵养的内容,后来想了想,就当自己的笔记吧.这次从新开始,未尝不是一个博客开始的好时机 ...

  7. sys.argv的妙用:python命令行参数列表的修改、增加、删除

    是否妙用取决于你怎么用 1.sys.argv是用来获取命令行参数的方法,本身是一个list.你搜其实用方法,这方面的介绍最多,这里不赘述 2.那么问题是:sys.argv可以赋值吗?可以扩充吗?可以修 ...

  8. [转]thrift系列 - 快速入门

    原文: http://blog.csdn.net/hrn1216/article/details/51274934 thrift 介绍,入门例子. thrift 是一个RPC框架,实现跨语言 ---- ...

  9. Asp.net MVC 简单分页 自做简单分页

    Asp.net MVC 简单分页:   public static string Pager(int page,int pageSize,int total)         {           ...

  10. 如何将Python的py程序打包成跨平台的exe文件

    在编写了自己的第一个可以爬写网页源代码的程序之后,发现如果在没有安装了pythonLDLE程序的计算机上根本就跑不出来.所以开始寻找可以将程序打包成跨平台运行的exe文件. 经过自己费力的谷歌没有一个 ...