Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
119040 | 胡海峰老师 | 扫雷游戏 | C++ | Accepted | 5 MS | 336 KB | 1369 | 2025-05-11 18:53:47 |
#include <iostream> #include <vector> #include <string> using namespace std; // 检查是否是雷 bool isMine(int i, int j, const vector<string>& a, int n, int m) { if (i < 0 || i >= n || j < 0 || j >= m) { return false; } return a[i][j] == '*'; } int main() { int n, m; cin >> n >> m; vector<string> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } vector<vector<int>> b(n, vector<int>(m, 0)); for (int x = 0; x < n; ++x) { for (int y = 0; y < m; ++y) { if (a[x][y] == '*') { b[x][y] = '*'; continue; } int t = 0; vector<pair<int, int>> directions = { {-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1} }; for (auto& dir : directions) { int dx = dir.first; int dy = dir.second; t += isMine(x + dx, y + dy, a, n, m); } b[x][y] = t; } } for (const auto& row : b) { for (const auto& num : row) { if (num == '*') { cout << "*"; } else { cout << num; } } cout << endl; } return 0; }