반응형
n = int(input())
mine_map=["."*(n+2)]
open_map=["."*(n+2)]
for _ in range(n):
  mine_map.append( "."+ input()+".")
for __ in range(n):
  open_map.append("."+ input()+".")
open_map.append("."*(n+2))
mine_map.append("."*(n+2))

finished = False
temp =[]
for column_num in range(1,n+1):
  for row_num in range(1,n+1):
    if mine_map[column_num][row_num] == "*":
      temp.append((column_num, row_num))
    count =0
    if mine_map[column_num+1][row_num] =="*":
      count += 1
    if mine_map[column_num+1][row_num+1] =="*":
      count += 1
    if mine_map[column_num+1][row_num-1] =="*":
      count += 1
    if mine_map[column_num][row_num+1] =="*":
      count += 1
    if mine_map[column_num][row_num-1] =="*":
      count += 1
    if mine_map[column_num-1][row_num] =="*":
      count += 1
    if mine_map[column_num-1][row_num-1] =="*":
      count += 1
    if mine_map[column_num-1][row_num+1] =="*":
      count += 1
    
    if open_map[column_num][row_num] == "x":
      if mine_map[column_num][row_num] == "*":
        finished = True
      else:
        open_map[column_num]= open_map[column_num][:row_num] + str(count) + open_map[column_num][row_num+1:]

if finished:
  for jj in temp:
    j,k = jj
    open_map[j]= open_map[j][:k] + "*" + open_map[j][k+1:]  

for ii in range(1,n+1):
  print(open_map[ii][1:-1])
반응형

+ Recent posts