'commit'
This commit is contained in:
31
TangDou/CSP-J/AcWingTraining/T4/462.cpp
Normal file
31
TangDou/CSP-J/AcWingTraining/T4/462.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
const int N = 110;
|
||||
// 依次枚举每个空格,然后统计八个方向上的相邻格子有没有地雷即可
|
||||
int n, m;
|
||||
char g[N][N];
|
||||
|
||||
int main() {
|
||||
cin >> n >> m;
|
||||
for (int i = 0; i < n; i++) cin >> g[i];
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < m; j++)
|
||||
if (g[i][j] == '*')
|
||||
cout << '*';
|
||||
else {
|
||||
int s = 0;
|
||||
// 8个方向一般玩的是9宫格,然后放弃自己
|
||||
for (int x = i - 1; x <= i + 1; x++)
|
||||
for (int y = j - 1; y <= j + 1; y++)
|
||||
if (x != i || y != j) {
|
||||
if (x >= 0 && x < n && y >= 0 && y < m && g[x][y] == '*') s++;
|
||||
}
|
||||
cout << s;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user