YTU 1099: Minesweeper
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的更多相关文章
- 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem B: Minesweeper(模拟扫雷)
Problem B: Minesweeper Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 29 Solved: 7[Submit][Status][W ...
- ytu 1057: 输入两个整数,求他们相除的余数(带参的宏 + 模板函数 练习)
1057: 输入两个整数,求他们相除的余数 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 177 Solved: 136[Submit][Status ...
- 启动tomcat时 错误: 代理抛出异常 : java.rmi.server.ExportException: Port already in use: 1099;
错误: 代理抛出异常 : java.rmi.server.ExportException: Port already in use: 1099; nested exception is: java ...
- poj 1099
http://poj.org/problem?id=1099 #include<stdio.h> #include<string.h> #include <iostrea ...
- 启动tomcat时 错误: 代理抛出异常 : java.rmi.server.ExportException: Port already in use: 1099的解决办法
一.问题描述 今天一来公司,在IntelliJ IDEA 中启动Tomcat服务器时就出现了如下图所示的错误:
- ytu 1058: 三角形面积(带参的宏 练习)
1058: 三角形面积 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 190 Solved: 128[Submit][Status][Web Boar ...
- idea启动tomcat失败,1099端口被占用
今天遇到一个问题,当使用idea启动一个tomat服务的时候,报错:不能连接本地1099端口. /Users/liqiu/soft/develop/apache-tomcat-/bin/catalin ...
- ACdream OJ 1099 瑶瑶的第K大 --分治+IO优化
这题其实就是一个求数组中第K大数的问题,用快速排序的思想可以解决.结果一路超时..原来要加输入输出优化,具体优化见代码. 顺便把求数组中第K大数和求数组中第K小数的求法给出来. 代码: /* * th ...
- ytu 1980:小鼠迷宫问题(DFS 深度优先搜索)
小鼠迷宫问题 Time Limit: 2 Sec Memory Limit: 64 MB Submit: 1 Solved: 1 [Submit][Status][Web Board] Desc ...
随机推荐
- jquery获取ul中li的值
- vsftpd系统用户配置详解
1.安装yum -y install pam pam-devel db4 de4-devel db4-uitls db4-tclyum -y install vsftpd 新建vsftpd系统用户:u ...
- bzoj3875 【Ahoi2014】骑士游戏 spfa处理后效性动规
骑士游戏 [故事背景] 长期的宅男生活中,JYY又挖掘出了一款RPG游戏.在这个游戏中JYY会 扮演一个英勇的骑士,用他手中的长剑去杀死入侵村庄的怪兽. [问题描述] 在这个游戏中,JYY一共有两种攻 ...
- PHP应用日期与时间
<?php/* 时间戳 * * 1. 是一个整数 * 2. 1970-1-1 到现在的秒数 1213212121 * * 2014-02-14 11:11:11 * * 02/14/2014 1 ...
- 转 蓝桥杯 历届试题 波动数列 [ dp ]
传送门 历届试题 波动数列 时间限制:1.0s 内存限制:256.0MB 锦囊1 锦囊2 锦囊3 问题描述 观察这个数列: 1 3 0 2 -1 1 -2 ... 这个 ...
- php责任链模式
php 责任链模式 又叫职责链模式.包含了一些命令对象和一些处理对象,每个处理对象决定它能处理那些命令对象,它也知道应该把自己不能处理的命令对象交下一个处理对象,该模式还描述了往该链添加新的处理对象的 ...
- 123. Best Time to Buy and Sell Stock III ~~
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- EsAlert
https://www.cnblogs.com/zhaishaomin/p/7417306.html https://blog.csdn.net/pujiaolin/article/details/5 ...
- POJ 3461 字符串出现次数 && HDU1711 字符串第一次出现的位置 模板题
Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 48387 Accepted: 19261 Descri ...
- Sudoku Killer--hdu1426(数独 跟上一题差不多 但是输入时问题)
http://acm.hdu.edu.cn/showproblem.php?pid=1426 注意输入问题就行 还是dfs #include<stdio.h> #include<st ...