标题:acm的一道问题,不知道为什么Wrong Answer
只看楼主
弓箭手789
Rank: 1
等 级:新手上路
帖 子:11
专家分:1
注 册:2013-7-31
结帖率:100%
 问题点数:0 回复次数:0 
acm的一道问题,不知道为什么Wrong Answer
Description
Have you ever played Minesweeper? It's a cute little game which comes within a certain Operating System which name we can't really remember. Well, the goal of the game is to find where are all the mines within a MxN field. To help you, the game shows a number in a square which tells you how many mines there are adjacent to that square. For instance, supose the following 4x4 field with 2 mines (which are represented by an * character):
*...
....
.*..
....

If we would represent the same field placing the hint numbers described above, we would end up with:
*100
2210
1*10
1110

As you may have already noticed, each square may have at most 8 adjacent squares.
Input
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 stands for the number of lines and columns of the field respectively. The next n lines contains exactly m characters and represent the field. Each safe square is represented by an "." character (without the quotes) and each mine square is represented by an "*" character (also without the quotes). The first field line where n = m = 0 represents the end of input and should not be processed.
Output
For each field, you must print the following message in a line alone:
Field #x:

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 adjacent mines to that square. There must be an empty line between field outputs.
Sample Input
4 4
*...
....
.*..
....
3 5
**...
.....
.*...
0 0

Sample Output
Field #1:
*100
2210
1*10
1110

Field #2:
**100
33200
1*100
结果正确,格式无误,但不能通过,希望高手赐教
#include<stdio.h>
#include<stdlib.h>
int judje(int a[101][101],int m,int n,int boundary,int boundary2)
{
    int s=0;
    if (a[m][n]==42)return 42;
    if (m-1>-1&&n-1>-1&&m-1<boundary&&n-1<boundary2&&a[m-1][n-1]==42)s++;
    if (m-1>-1&&n>-1&&m-1<boundary&&n<boundary2&&a[m-1][n]==42)s++;
    if (m-1>-1&&n+1>-1&&m-1<boundary&&n+1<boundary2&&a[m-1][n+1]==42)s++;
    if (m>-1&&n-1>-1&&m<boundary&&n-1<boundary2&&a[m][n-1]==42)s++;
    if (m>-1&&n+1>-1&&m<boundary&&n+1<boundary2&&a[m][n+1]==42)s++;
    if (m+1>-1&&n-1>-1&&m+1<boundary&&n-1<boundary2&&a[m+1][n-1]==42)s++;
    if (m+1>-1&&n>-1&&m+1<boundary&&n<boundary2&&a[m+1][n]==42)s++;
    if (m+1>-1&&n+1>-1&&m+1<boundary&&n+1<boundary2&&a[m+1][n+1]==42)s++;
    return s;
}
int main()
{
    int a[101][101],b1,b2,j,i,s=1;
    scanf("%d %d",&b1,&b2);
    getchar();
    while (1)
    {
          if(b1==0&&b2==0)break;
          for (i=0;i<=b1;i++)
              for (j=0;j<=b2;j++)
                  a[i][j]=0;
          for (i=0;i<b1;i++)
              {
                  for (j=0;j<b2;j++)
                  scanf("%c",&a[i][j]);
                  getchar();
              }
          for (i=0;i<b1;i++)
              for (j=0;j<b2;j++)
                  a[i][j]=judje(a,i,j,b1,b2);
          printf("Field #%d:\n",s++);
          for (i=0;i<b1;i++)
              {
                  for (j=0;j<b2;j++)
                  if (a[i][j]==42)
                  printf("%c",a[i][j]);
                  else printf("%d",a[i][j]);
                  printf("\n");
              }
          printf("\n");
          scanf("%d %d",&b1,&b2);
          getchar();
    }
    return 0;
}
搜索更多相关主题的帖子: number remember represent following character 
2013-08-02 20:14



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-418491-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.034286 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved