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.

样例输入

  1. 4 4
  2. *...
  3. ....
  4. .*..
  5. ....
  6. 3 5
  7. **...
  8. .....
  9. .*...
  10. 0 0

样例输出

  1. Field #1:
  2. *100
  3. 2210
  4. 1*10
  5. 1110
  6.  
  7. Field #2:
  8. **100
  9. 33200
  10. 1*100
  1. #include <stdio.h>
  2. #include <string.h>
  3. int main()
  4. {
  5. char lei[120][120];
  6. int ci=0,n,m;
  7. while(~scanf("%d%d",&n,&m)&&(n||m))
  8. {
  9. memset(lei,'0',sizeof(lei));
  10. for(int i=1; i<=n; i++)
  11. for(int j=1; j<=m; j++)
  12. {
  13. char x;
  14. scanf(" %c",&x);
  15. if(x=='*')
  16. {
  17. lei[i][j]='*';
  18. for(int ii=i-1; ii<=i+1; ii++)
  19. for(int jj=j-1; jj<=j+1; jj++)
  20. if(lei[ii][jj]!='*')lei[ii][jj]++;
  21. }
  22. }
  23. printf("Field #%d:\n",++ci);
  24. for(int i=1; i<=n; i++)
  25. for(int j=1; j<=m; j++)printf(j!=m?"%c":"%c\n",lei[i][j]);
  26. printf("\n");
  27. }
  28. return 0;
  29. }

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

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. 81. Spring Boot集成JSP疑问【从零开始学Spring Boot】

    [原创文章,转载请注明出处] 针对文章: ()Spring Boot 添加JSP支持[从零开始学Spring Boot] 有网友提了这么一些疑问: 1.Spring Boot使用jsp时,仍旧可以打成 ...

  2. HDU1021-Fibonacci Again,,找规律就好了~~~

    Fibonacci Again Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. 洛谷 P2008 大朋友的数字

    DP,动态规划   树状数组   最长不下降子序列 by  GeneralLiu 题目 就是说给一串由 0~9 组成的序列 求 以 i (1~n) 结尾 的 最长不下降子序列 的 和 (最长不下降子序 ...

  4. 【区间筛】2017多校训练四 HDU6069 Counting Divisors

    http://acm.hdu.edu.cn/showproblem.php?pid=6069 [题意] 给定l,r,k,求 d(n)是n的因子个数 [思路] [Accepted] #include&l ...

  5. MYSQL常见运算符和函数【重要】

    字符函数 (1)CONCAT():字符连接 SELECT CONCAT(‘IMOOC’,’-‘,’MySQL’);//IMOOC-MySQL SELECT CONCAT (first_name,las ...

  6. msp430项目编程26

    msp430中项目---串行存储器接口 1.I2C工作原理 2.I2C通信协议 3.代码(显示部分) 4.代码(功能实现) 5.项目总结 msp430项目编程 msp430入门学习

  7. Office EXCEL 2010如何启用宏编辑器,打开VB编辑器

    文件-选项-主选项卡,勾选开发工具 然后在开发工具中找到Visual Basic编辑器,打开代码

  8. stl 之set图解

    使用set或multiset之前,必须增加头文件<set> Set.multiset都是集合类,区别在与set中不同意有反复元素,multiset中同意有反复元素. sets和multis ...

  9. AspNetPager真假分页对照实例

    从開始学习BS已经有一段时间了. 对于BS的设计,都是进行的网页设计,当中包含从数据库中取出来的数据.显示在页面上.曾经在CS中,都是使用GridView等表格控件进行显示,因为数据小.并且右側又有滚 ...

  10. hdoj 2046 骨牌铺方格 【DP】+【斐波那契】

    dp果然不是好学的... 第n个,即2*n时,可由第n-1个的竖直排列再加一个,和第n-2个中横着排两个 所以f(n) = 1×f(n-1) + 1×f(n-2): 骨牌铺方格 Time Limit: ...