提交时间:2026-04-10 15:13:08

运行 ID: 87029

#include <iostream> #include <string> using namespace std; int main() { int n, m; cin >> n >> m; char a[105][105]; for (int i = 0; i < n; i++) { cin >> a[i]; } int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i][j] == '*') { cout << '*'; } else { int cnt = 0; for (int d = 0; d < 8; d++) { int x = i + dx[d]; int y = j + dy[d]; if (x >= 0 && x < n && y >= 0 && y < m && a[x][y] == '*') { cnt++; } } cout << cnt; } } cout << endl; } return 0; }