Minesweeper

Description

Minesweeper Have you ever played Minesweeper? This cute little game comes with certain operating system whose name we can't remember. The goal of the game is to find where all the mines are located within field. The game shows number in square which tells you how many mines there are adjacent to that square. Each square has at most eight adjacent squares. The field on the left contains two mines, each represented by ``*'' 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

Input

The input will consist of an arbitrary number of fields. The first line of each field contains two integers and n, m<100) which stand for the number of lines and columns of the field, respectively. Each of the next lines contains exactly characters, representing the field. Safe squares are denoted by ``.'' and mine squares by ``*,'' both without the quotes. The first field line where represents the end of input and should not be processed.

Output

For each field, print the message Field #x: on line alone, where stands for the number of the field starting from 1. The next 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.

Sample Input

*...

.... 

.*.. 

.... 

**... 

..... 

.*... 

0

Sample Output

Field #1: 

*100 

2210 

1*10

 1110 

 Field #2: 

**100 

33200 

1*100 

 

 

1. #include<stdio.h>

2. int main()

3. {

4.     int i,j;

5.     char a[102][102];

6.     for(i=0; i<101; i++)for(j=0; j<101; j++)a[i][j]='0';

7.     int m,n;

8.     int jishu=0,b=0;

9.     for(;;)

10.     {

11.         scanf("%d%d",m,n)

12.         b++;

13.         if(m==0&&n==0)break;

14.         for(i=1; i<=m; i++)for(j=1; j<=n; j++)scanf("%c",&a[i][j]);

15.         for(i=1; i<=m; i++)for(j=1; j<=n; j++)

16.             {

17.                 if(a[i][j]!='*')

18.                 {

19.                     if(a[i-1][j-1]=='*')jishu++;

20.                     if(a[i-1][j]=='*')jishu++;

21.                     if(a[i-1][j+1]=='*')jishu++;

22.                     if(a[i][j-1]=='*')jishu++;

23.                     if(a[i][j+1]=='*')jishu++;

24.                     if(a[i+1][j-1]=='*')jishu++;

25.                     if(a[i+1][j]=='*')jishu++;

26.                     if(a[i+1][j+1]=='*')jishu++;

27.                     a[i][j]=jishu+'0';

28.                     jishu=0;

29.                 }

30.             }

31.         if(b!=1)printf("\n")

32.         printf("Field #%d:\n",b);

33.         for(i=1; i<=m; i++)for(j=1; j<=n; j++)

34.             {

35.                 printf("%c",a[i][j]);

36.                 if(j==n)printf("\n");

37.             }

38.     }

39.     return 0;

40. }

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值