hturtle
2022-08-06 19:50
采纳率: 100%
浏览 27

洛谷P2670 样例过不了,1AC


#include<cstdio>
using namespace std;

int n = 0 , m = 0;
int ans = 0;

int main()
{
    scanf("%d%d",&n,&m);
    char excel[n][m];
    for (int i = 0 ; i < n ; i++)
    {
        for (int j = 0 ; j < m ; j++)
        {
            scanf("%c",&excel[i][j]);
        }
    }
    
    for (int i = 0 ; i < n ; i++)
    {
        for (int j = 0 ; j < m ; j++)
        {
            if (excel[i][j] == '*')
            {
                printf("*");
                continue;
            }
            
            if (i-1 != -1)
            {
                if (excel[i-1][j] == '*') ans++;
            }
            if (i-1 != -1 && j-1 != -1)
            {
                if (excel[i-1][j-1] == '*') ans++;
            }
            if (j-1 != -1)
            {
                if (excel[i][j-1] == '*') ans++;
            }
            if (j-1 != -1 && i+1 != n)
            {
                if (excel[i+1][j-1] == '*') ans++;
            }
            if (i+1 != n)
            {
                if (excel[i+1][j] == '*') ans++;
            }
            if (i+1 != n && j+1 != m)
            {
                if (excel[i+1][j+1] == '*') ans++;
            }
            if (j+1 != m)
            {
                if (excel[i][j+1] == '*') ans++;
            }
            if (i-1 != -1 && j+1 != m)
            {
                if (excel[i-1][j+1] == '*') ans++;
            }
            
            printf("%d",ans);
            ans = 0;
        }
        printf("\n");
    }
    return 0;
}

2条回答 默认 最新

相关推荐 更多相似问题