브루트포쓰
import sys
input = sys.stdin.readline
n = int(input())
mines = [list(input().rstrip()) for _ in range(n)]
maps = [list(input().rstrip()) for _ in range(n)]
di = [0,0,-1,1,1,1,-1,-1]
dj = [1,-1,0,0,1,-1,1,-1]
flag = False
for i in range(n):
for j in range(n):
if maps[i][j]=='x':
if mines[i][j]=='*':
flag = True
continue
cnt = 0
for k in range(8):
if 0<= i+di[k] < n and 0 <= j+dj[k] < n and mines[i+di[k]][j+dj[k]]=='*':
cnt += 1
maps[i][j] = str(cnt)
if flag:
for i in range(n):
for j in range(n):
if mines[i][j]=='*':
maps[i][j] = '*'
for row in maps:
print(''.join(row))
'practivceAlgorithm > 백준' 카테고리의 다른 글
[백준][Python] 2571 색종이3 (0) | 2021.09.04 |
---|---|
[백준][Python] 2644 촌수계산 (0) | 2021.09.04 |
[백준][Python] 1719 택배 : 플로이드워셜 경로 (0) | 2021.09.04 |
[백준][Python] 2002 추월 (0) | 2021.09.03 |
[백준][Python] 21966 (중략) (0) | 2021.09.03 |