全部评论 12

  • #include <iostream>
    #include <vector>

    using namespace std;

    int main() {
    int n, m;
    cin >> n >> m;

    vector<vector<char>> grid(n, vector<char>(m));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> grid[i][j];
        }
    }
    
    // 输出结果
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (grid[i][j] == '*') {
                cout << '*';
            } else {
                int count = 0;
                // 检查周围8个方向
                for (int dx = -1; dx <= 1; ++dx) {
                    for (int dy = -1; dy <= 1; ++dy) {
                        if (dx == 0 && dy == 0) continue; // 跳过自身
                        int nx = i + dx, ny = j + dy;
                        if (nx >= 0 && nx < n && ny >= 0 && ny < m && grid[nx][ny] == '*') {
                            count++;
                        }
                    }
                }
                cout << count;
            }
        }
        cout << endl;
    }
    
    return 0;
    

    }
    Given by AI.

    2024-12-15 来自 浙江

    1
  • \正确答案
    #include<stdio.h>
    int main(void)
    {
    char a[101][101];
    int sum[100][100]={0};
    int j,i,n,m;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
    {
    scanf("%s",a[i]);getchar();
    }
    for(i=0;i<n;i++)
    {
    for(j=0;j<m;j++)
    {
    if(a[i][j]'*')
    {sum[i][j]=-1; continue;
    }
    if(a[i-1][j-1]
    '')
    sum[i][j]++;
    if(a[i-1][j]=='
    ')
    sum[i][j];
    if(a[i-1][j+1]=='*')
    sum[i][j]
    ;
    if(a[i][j-1]'*')
    sum[i][j]++;
    if(a[i][j+1]
    '')
    sum[i][j]++;
    if(a[i+1][j-1]=='
    ')
    sum[i][j];
    if(a[i+1][j]=='*')
    sum[i][j]
    ;
    if(a[i+1][j+1]=='')
    sum[i][j];
    }
    }
    for(i=0;i<n;i
    )
    {
    for(j=0;j<m;j++)
    {
    if(sum[i][j]!=-1)
    printf("%d",sum[i][j]);
    else putchar('
    ');
    }
    putchar('\n');
    }
    return 0;
    }

    2025-08-22 来自 四川

    0
  • 你****************************************************************

    2025-08-20 来自 浙江

    0
  • 你编了个dr啊!:
    编译错误: /code/judger/test/1892807411052548096/main.cpp:17:11: error: empty character constant
    17 | if(a[i][j]'')cout<<"";
    | ^~
    /code/judger/test/1892807411052548096/main.cpp: In function 'int main()':
    /code/judger/test/1892807411052548096/main.cpp:17:11: error: expected ')' before '\x0'
    17 | if(a[i][j]'')cout<<"";
    | ~ ^~
    | )
    /code/judger/test/1892807411052548096/main.cpp:23:11: error: expected ')' before ''
    23 | if(a[l][r]'
    ')
    | ~ ^~~
    | )

    2025-02-21 来自 云南

    0
  • What the hell does ac dog give birth to? Or an error?

    2024-12-15 来自 浙江

    0
  • 编译错误: /code/judger/test/1868138038275731456/main.cpp:17:11: error: empty character constant
    17 | if(a[i][j]'')cout<<"";
    | ^~
    /code/judger/test/1868138038275731456/main.cpp: In function 'int main()':
    /code/judger/test/1868138038275731456/main.cpp:17:11: error: expected ')' before '\x0'
    17 | if(a[i][j]'')cout<<"";
    | ~ ^~
    | )
    /code/judger/test/1868138038275731456/main.cpp:23:11: error: expected ')' before ''
    23 | if(a[l][r]'
    ')
    | ~ ^~~
    | )

    2024-12-15 来自 浙江

    0
  • I don't want to speak Chinese.

    2024-12-15 来自 浙江

    0
  • The error is multiplied by 1000.

    2024-12-15 来自 浙江

    0
  • 报错x4

    2024-11-06 来自 广东

    0
  • 编译错误: /code/judger/test/1836736091462660096/main.cpp:17:11: error: empty character constant
    if(a[i][j]'')cout<<"";
    ^~
    /code/judger/test/1836736091462660096/main.cpp: In function 'int main()':
    /code/judger/test/1836736091462660096/main.cpp:17:11: error: expected ')' before '\x0'
    /code/judger/test/1836736091462660096/main.cpp:23:11: error: expected ')' before ''
    if(a[l][r]'
    ')
    ^~~

    2024-09-19 来自 天津

    0
  • 报错x3

    2024-07-05 来自 北京

    0
  • 报错

    2024-06-05 来自 广东

    0
暂无数据

提交答案之后,这里将显示提交结果~

首页