题解 | #扫雷#
扫雷
https://www.nowcoder.com/practice/d5f277427d9a4cd3ae60ea6c276dddfd
#include<stdio.h> #include<string.h> int main() { int n, m, count; scanf("%d %d", &n, &m); char A[1002][1002] = {0}; getchar(); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { A[i][j] = getchar(); } getchar(); } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (A[i][j] == '.') { count = 0; if (A[i - 1][j - 1] == '*') count++; if (A[i - 1][j] == '*') count++; if (A[i - 1][j + 1] == '*') count++; if (A[i][j - 1] == '*') count++; if (A[i][j + 1] == '*') count++; if (A[i + 1][j - 1] == '*') count++; if (A[i + 1][j] == '*') count++; if (A[i + 1][j + 1] == '*') count++; A[i][j] = '0' + count; printf("%c", A[i][j]); } else if (A[i][j] == '*') printf("%c", A[i][j]); } printf("\n"); } }