ac代码:
#include <iostream>
using namespace std;
const int N = 110;
int n, m;
int arr[N][N];
int dx[8] = {0, 1, 0, -1, -1, 1, -1, 1};
int dy[8] = {1, 0, -1, 0, -1, 1, 1, -1};
int main()
{
cin >> n >> m;
for(int i = 0; i < n; i ++)
for(int j = 0; j < m; j ++)
cin >> arr[i][j];
for(int i = 0; i < n; i ++)
{
for(int j = 0; j < m; j ++)
{
int cnt = 0;
if(arr[i][j] == 1) cout << 9 << " ";
else
{
for(int p = 0; p < 8; p ++)
{
int x = i + dx[p], y = j + dy[p];
if(x >=0 && y >= 0)
if(arr[x][y] == 1)
cnt ++;
}
cout << cnt << " ";
}
}
cout << endl;
}
return 0;
}