30分求助,谢谢
#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 i = 0; i < 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;
}