d625.
踩地雷真好玩
--
jack1
| From: [124.11.192.89] |
發表日期
:
2017-08-06 11:42
#include <bits/stdc++.h>
using namespace std;
int N;
char arr[105][105];
int cnt[105][105];
int dx[]={ -1, 0, 1, -1, 1, -1, 0, 1 };
int dy[]={ -1, -1, -1 , 0 , 0 , 1 , 1 , 1 };
int main(){
cin >> N;
for ( int i = 0 ; i < N; i++ )
cin >> arr[i];
for ( int i = 0 ; i < N; i++ )
for ( int j = 0 ; j < N; j++ )
cnt[i][j] = 0;
for ( int i = 0 ; i < N; i++ )
for ( int j = 0 ; j < N; j++ )
if ( arr[i][j] == '-' ){
for ( int d = 0 ; d < 8 ; d++ ){
int nx = j + dx[d];
int ny = i + dy[d];
if ( nx < 0 || ny < 0 || nx >= N || ny >= N )
continue;
else{
if ( arr[ny][nx] == '*' )
cnt[i][j]++;
}
}
}
for ( int i = 0 ; i < N ; i++ ){
for ( int j = 0 ; j < N ; j++ ){
if ( arr[i][j] == '*' )
cout << '*';
else if ( cnt[i][j] == 0 )
cout << '-';
else
cout << cnt[i][j];
}
cout << endl;
}
return 0;
}