[noip2015pj] 扫雷游戏

题目链接

题解:水题重游

#include
#include
#include
using namespace std;
int a[1100][1100];
int main()
{
    int n,m,i,j;char c[1100];
    scanf("%d%d",&n,&m);
    memset(a,0,sizeof(a));
    for (i=1;i<=n;i++)
    {
        scanf("%s",c+1);
        int len=strlen(c+1);
        for (j=1;j<=len;j++)
        {
            if (c[j]=='*')
            {
                a[i][j]=999999;//999999设为雷的标记 
                a[i-1][j-1]++;//八个方向都++ 
                a[i-1][j]++;
                a[i-1][j+1]++;
                a[i][j-1]++;
                a[i][j+1]++;
                a[i+1][j-1]++;
                a[i+1][j]++;
                a[i+1][j+1]++;
            }
        }

    }
    for (i=1;i<=n;i++)
    {
        for (j=1;j<=m;j++)
        {
        if (a[i][j]>10000) //为雷 
            printf("*");
        else //安全区域 
            printf("%d",a[i][j]);
        }
        printf("\n");
    }
    return 0;
}

你可能感兴趣的:(模拟)