-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbj_4396.py
More file actions
50 lines (40 loc) · 1.27 KB
/
Copy pathbj_4396.py
File metadata and controls
50 lines (40 loc) · 1.27 KB
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
import sys
sys.stdin = open('bj_4396_in.txt', 'r')
input = sys.stdin.readline
n = int(input().strip())
boards = []
for _ in range(n):
row = list(input().strip())
boards.append(row)
# print(boards)
visited = [list(input().strip()) for _ in range(n)]
# print(visited)
# 8방 탐색
dr = [-1, -1, 0, 1, 1, 1, 0, -1]
dc = [0, 1, 1, 1, 0, -1, -1, -1]
flag = False
answer = [['.' for _ in range(n)] for _ in range(n)]
# print(answer)
for r in range(n):
for c in range(n):
# print(r,c)
if visited[r][c] == 'x': #방문한 위치면
# 방문한 위치의 지도값 체크
if boards[r][c] == '*': #지뢰 발견시 지뢰플래그 업데이트
flag = True
else: #지뢰가 아니면 8방 탐색
cnt = 0
for i in range(8): #8방
nr = r + dr[i]
nc = c + dc[i]
if 0 <= nr < n and 0 <= nc < n:
if boards[nr][nc] == '*': #지뢰가 주변에 있으면
cnt += 1
answer[r][c] = cnt
if flag:
for r in range(n):
for c in range(n):
if boards[r][c] == '*':
answer[r][c] = '*'
for row in answer:
print(''.join(map(str, row)))