不是题解 | #扫雷游戏#
扫雷游戏
https://ac.nowcoder.com/acm/problem/16491
- 2021年04月15日17:38:34愚蠢的代码
#include <iostream> using namespace std; int a[10010][10010] = {0}; int main() { int row, col; cin >> row >> col; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { cin >> a[i][j]; } } for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { int count = 0; if (a[i][j] == '*') continue; if (a[i - 1][j] == '*') count++; else if (a[i + 1][j] == '*') count++; else if (a[i][j - 1] == '*') count++; else if (a[i][j + 1] == '*') count++; else if (a[i + 1][j + 1] == '*') count++; else if (a[i - 1][j + 1] == '*') count++; else if (a[i + 1][j - 1] == '*') count++; else if (a[i - 1][j - 1] == '*') count++; a[i][j] = count; count = 0; } } for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { cout << a[i][j] << endl; } } return 0;
- 2021年04月15日18:06:55
#include <iostream> using namespace std; int dx[] = {1, 1, 1, 0, 0, -1, -1, -1}; int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; const int maxn = 105; char g[maxn][maxn]; int n, m; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> g[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (g[i][j] != '*') { int count = 0; for (int k = 0; k < 8; k++) { if (g[i + dx[k]][j + dy[k]] == '*') count++; } cout << count; } else { cout << '*'; } } cout << endl; // 行末空格 } return 0; }