求助,玄关
查看原帖
求助,玄关
1319442
Allen_Cheng楼主2024/7/22 21:29

20分,部分RE

#include <iostream>
#include <string>
using namespace std;

int n, m;
const int N = 120;
string mp[N];
int dx[] = { 1, -1, 0, 0, 1, -1, 1, -1 };
int dy[] = { 0, 0, -1, 1, 1, -1, -1, 1 };
int cnt;

int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> mp[i];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (mp[i][j] == '*')
            {
                cout << '*';
                continue;
            }
            cnt = 0;
            for (int k = 0; k < 8; i++)
            {
                int nx = i + dx[i], ny = j + dy[i];
                if (nx < 0 || nx >= n || ny < 0 || ny >= n) continue;
                if (mp[nx][ny] == '*') cnt++;
            }
            cout << cnt;
        }
        cout << endl;
    }
    return 0;
}
2024/7/22 21:29
加载中...