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. Python 单向队列Queue模块详解

    Python 单向队列Queue模块详解 单向队列Queue,先进先出 '''A multi-producer, multi-consumer queue.''' try: import thread ...

  2. Go内建变量类型

    package main import ( "math/cmplx" "fmt" "math" ) //内建变量类型: // bool , ...

  3. spoj 839 最小割+二进制

    #include<stdio.h> #include<string.h> #include<queue> using namespace std; #define ...

  4. 两行代码搞定UI主流框架

    XCNavTab XCNavTab适用于快速搭建NavigationController和TabBarController相结合的框架 https://github.com/xiaocaiabc/XC ...

  5. POJ2014 Flow Layout

      Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3161   Accepted: 2199 Description A f ...

  6. 自用的博客皮肤CSS代码

    是在默认皮肤simple memory的基础上进行的魔改 /*****home和头部开始**************************/ #home { margin: 0 auto; widt ...

  7. http的N种请求

    GET通过请求URI得到资源 POST,用于添加新的内容 PUT用于修改某个内容 DELETE,删除某个内容 CONNECT,用于代理进行传输,如使用SSL OPTIONS询问可以执行哪些方法 PAT ...

  8. hdu3622 2-sat问题,二分+判断有无解即可。

    /*2-sat问题初破!题意:每一对炸弹只能选一个(明显2-sat),每个炸弹半径自定,爆炸范围不可 相交,求那个最小半径的最大值(每种策略的最小半径不同).思:最优解:必然是选择的点最近 的俩个距离 ...

  9. .htaccess重写、安全防护、文件访问权限

    今天在<外刊IT评论>上看见了关于.htaccess的使用总结,觉得很不错的,因为wp博客还有其他的php的web服务站点好多都是用.htaccess来管理比如效率以及安全的问题,有必要来 ...

  10. 使用uncss去除无用的CSS

    1.安装nodejs,gulp,gulp_uncss 1.1.说明:gulp-uncss 是gulp的一个插件.gulp是基于nodejs,理所当然需要安装nodejs: 1.2.安装:打开nodej ...