啊?
2024-06-09 21:09:44
发布于:浙江
#include <iostream>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
char a[105][105];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
// 计算地雷格周围非地雷格的数量
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i][j] == '*') {
for (int k = 0; k < 8; k++) {
int ni = i + dirs[k][0], nj = j + dirs[k][1];
if (ni >= 1 && ni <= n && nj >= 1 && nj <= m && a[ni][nj] == '?') {
a[ni][nj] -= '0';
}
}
}
}
}
// 输出结果
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cout << (a[i][j] < '0' ? a[i][j] + '0' : a[i][j]);
}
cout << endl;
}
return 0;
}
// 定义邻接格子的偏移量
const int dirs[8][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1},
{0, 1}, {1, -1}, {1, 0}, {1, 1}};
全部评论 1
编译错误: /code/judger/test/1825851330794782720/main.cpp: In function 'int main()':
/code/judger/test/1825851330794782720/main.cpp:19:34: error: 'dirs' was not declared in this scope
int ni = i + dirs[k][0], nj = j + dirs[k][1];
^~~~
/code/judger/test/1825851330794782720/main.cpp:19:34: note: suggested alternative: 'div'
int ni = i + dirs[k][0], nj = j + dirs[k][1];
^~~~
div
/code/judger/test/1825851330794782720/main.cpp:20:47: error: 'nj' was not declared in this scope
if (ni >= 1 && ni <= n && nj >= 1 && nj <= m && a[ni][nj] == '?') {
^~
/code/judger/test/1825851330794782720/main.cpp:20:47: note: suggested alternative: 'ni'
if (ni >= 1 && ni <= n && nj >= 1 && nj <= m && a[ni][nj] == '?') {
^~
...2024-08-20 来自 天津
0嗯~
2024-08-20 来自 天津
0acgo的
2024-08-20 来自 浙江
0
有帮助,赞一个