Minesweeper

来源:互联网 发布:软件工作量估计案例 编辑:程序博客网 时间:2024/03/28 18:03

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