正经题解
2026-08-31 22:19:48
发布于:广东
11阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
char mp[505][505];
int ok(char mp[][505], int one, int two) {
int bom = 8;
if (mp[one - 1][two - 1] != '*') bom--;
if (mp[one - 1][two] != '*') bom--;
if (mp[one - 1][two + 1] != '*') bom--;
if (mp[one][two - 1] != '*') bom--;
if (mp[one][two + 1] != '*') bom--;
if (mp[one + 1][two - 1] != '*') bom--;
if (mp[one + 1][two] != '*') bom--;
if (mp[one + 1][two + 1] != '*') bom--;
return bom;
}
int main() {
int n, m, q;
cin >> n >> m >> q;
for (int i = 0; i <= n + 1; i++) {
for (int j = 0; j <= m + 1; j++) {
mp[i][j] = '0';
}
}
for (int i = 1; i <= q; i++) {
int x, y;
cin >> x >> y;
mp[x][y] = '*';
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (mp[i][j] == '*') {
cout << "*";
} else {
cout << ok(mp, i, j);
}
cout << " ";
}
cout << "\n";
}
return 0;
}
这里空空如也







有帮助,赞一个