模拟与高精度 P2670 扫雷游戏
题目
https://www.luogu.com.cn/problem/P2670
代码
#include<iostream> #include<cstdio> #include<string> #include<cstring> using namespace std; int answer[200][200]; #define inf 500 int main() { int n, m; string tmp; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { cin >> tmp; for (int j = 0; j < m; j++) { if (tmp[j] == '*') { if (i - 1 >= 0 && j - 1 >= 0)answer[i - 1][j - 1]++; if (i - 1 >= 0)answer[i - 1][j]++; if ( j - 1 >= 0)answer[i][j - 1]++; answer[i][j] = -inf; if (i +1 <n && j -1>=0)answer[i + 1][j-1]++; if (i + 1 <n )answer[i + 1][j]++; if (i - 1 >= 0 && j + 1<m)answer[i - 1][j + 1]++; if ( j + 1 <m)answer[i][j + 1]++; if (i + 1 <n && j +1<m)answer[i + 1][j + 1]++; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (answer[i][j] < 0) printf("*"); else printf("%d", answer[i][j]); } printf("\n"); } }