AcWing 462. 扫雷游戏
原题链接
简单
作者:
Value
,
2020-09-30 08:46:15
,
所有人可见
,
阅读 464
#include <iostream>
using namespace std;
const int N = 110;
char a[N][N];
int dic[8][2] = {
{-1, 0}, {-1, 1}, {0, 1}, {1, 1},
{1, 0}, {1, -1}, {0, -1}, {-1, -1}
};
int cmp(int x, int y){
int cnt = 0;
for(int i = 0; i < 8; i ++ ){
if(a[x + dic[i][0]][y + dic[i][1]] == '*') cnt ++ ;
}
return cnt;
}
int main(){
int n, m; cin >> n >> m;
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] == '*') cout << a[i][j];
else cout << cmp(i, j);
}
cout << endl;
}
return 0;
}