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. loadrunner 场景设计-手工场景设计

    概述 通过选择需要运行的脚本,分配运行脚本的负载生成器,在脚本中分配Vuser来建立手工场景 手工场景就是自行设置虚拟用户的变化,主页是通过设计用户的添加和减少过程,来模拟真实的用户请求模型,完成负载 ...

  2. Leetcode 221.最大的正方形

    最大的正方形 在一个由 0 和 1 组成的二维矩阵内,找到只包含 1 的最大正方形,并返回其面积. 示例: 输入: 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0 输出 ...

  3. Python和Excel

    # -*- coding: UTF-8 -*- import xlwt import StringIO # 将数据保存成excel def write_data(data, tname): file ...

  4. CodeForces 610B-Vika and Squares,有坑点,不是很难~~

    B. Vika and Squares time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. 爱在心中(codevs 2822)

    题目描述 Description “每个人都拥有一个梦,即使彼此不相同,能够与你分享,无论失败成功都会感动.爱因为在心中,平凡而不平庸,世界就像迷宫,却又让我们此刻相逢Our Home.” 在爱的国度 ...

  6. 【ZJOI2017 Round1练习】D2T3 counter(线段树)

    题意: 思路: 预处理出b[i]代表i位置之前比a[i]小的数的个数 以每个数为结尾的组数是线段树中(1,a[i]-1) 对于a[i]换到最后,相当于线段树中(a[i]+1,n)-- 交换后b[i]又 ...

  7. THUWC2018 暴力+爆炸记

    Day 0 没有Day0. Day 1 签到然后去宿舍,环境还行,比某偏远山区要强多了,不过这热水有点难拿??看RP有遇到煮好水的饮水机就拿,没有就苟矿泉水. 中午,那个餐还是挺好吃的,不过餐费40就 ...

  8. 《TCP/IP详解卷1:协议》——第2章:链路层(转载)

    1.引言 从图1-4可以看出,在TCP/IP协议族中,链路层主要有三个目的: (1)为IP模块发送和接收IP数据报: (2)为ARP模块发送ARP请求和接收ARP应答. (3)为RARP发送RARP请 ...

  9. oc温习二:基本运算及基本运算符

    C语言一共有34种运算符,如下: 运算符分类: 1.按照功能划分: (1)算术运算符 + 加法运算符 - 减法运算符 或者负值运算符 * 乘法运算符 / 除法运算符 % 模运算符,或者取余运算符,要求 ...

  10. Eventquery.vbs

    https://docs.microsoft.com/en-us/previous-versions/orphan-topics/ws.10/cc772995(v=ws.10)