-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP2670.cpp
More file actions
40 lines (36 loc) · 728 Bytes
/
P2670.cpp
File metadata and controls
40 lines (36 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<string> grid(n);
for (int i = 0; i < n; i++) {
cin >> grid[i];
}
// 方向数组:8个方向
const int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (grid[i][j] == '*') {
cout << '*';
} else {
int count = 0;
for (int k = 0; k < 8; k++) {
int ni = i + dx[k];
int nj = j + dy[k];
if (ni >= 0 && ni < n && nj >= 0 && nj < m) {
if (grid[ni][nj] == '*') {
count++;
}
}
}
cout << count;
}
}
cout << '\n';
}
return 0;
}