/
Mine Sweeper(TJU).cpp
66 lines (65 loc) · 1.19 KB
/
Mine Sweeper(TJU).cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <cstdio>
#include <cstring>
#include <iostream>
#include <math.h>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <ctime>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
using namespace std;
int po[50][50];
char red[50];
int sx[]={1,1,1,0,0,-1,-1,-1};
int sy[]={1,0,-1,1,-1,1,0,-1};
queue<pair<int,int> >q;
char ploca[50][50];
char isp[50][50];
int main(){
memset(po,0,sizeof po);
memset(isp,0,sizeof isp);
int n;
scanf("%d",&n);
for(int x=0;x<n;x++){
scanf("%s",ploca[x]);
for(int y=0;y<n;y++)
if(ploca[x][y]=='*')
q.push(make_pair(x,y));
}
int a,b;
while(!q.empty()){
a=q.front().first,b=q.front().second;
for(int y=0;y<8;y++){
po[a+sx[y]][b+sy[y]]++;
}
q.pop();
}
bool tako=0;
for(int x=0;x<n;x++){
scanf("%s",red);
for(int y=0;y<n;y++)
if(red[y]=='x'){
if(ploca[x][y]=='*')
tako=1;
isp[x][y]='0'+po[x][y];
}else
isp[x][y]='.';
}
if(tako)
for(int x=0;x<n;x++)
for(int y=0;y<n;y++)
if(ploca[x][y]=='*')
isp[x][y]='*';
for(int x=0;x<n;x++)
printf("%s\n",isp[x]);
}