Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- size = int(input())
- matrix = []
- for _ in range(size):
- line = '_' * size
- matrix.append(list(line))
- bombs = int(input())
- bomb_list = []
- for _ in range(bombs):
- bomb_row, bomb_col = [int(i) for i in input().strip('()').split(', ')]
- bomb_list.append([bomb_row, bomb_col])
- for row in range(size):
- for col in range(size):
- if [row, col] in bomb_list:
- matrix[row][col] = '*'
- def check_around(size, row, col):
- result = 0
- # up row - 1, col
- if 0 <= row - 1 < size and 0 <= col < size and matrix[row - 1][col] == '*':
- result += 1
- # down row + 1, col
- if 0 <= row + 1 < size and 0 <= col < size and matrix[row + 1][col] == '*':
- result += 1
- # left row, col - 1
- if 0 <= row < size and 0 <= col - 1 < size and matrix[row][col - 1] == '*':
- result += 1
- # right row, col + 1
- if 0 <= row < size and 0 <= col + 1 < size and matrix[row][col + 1] == '*':
- result += 1
- # up_left_corner row - 1, col - 1
- if 0 <= row - 1 < size and 0 <= col - 1 < size and matrix[row - 1][col - 1] == '*':
- result += 1
- # down_left_corner row + 1, col - 1
- if 0 <= row + 1 < size and 0 <= col - 1 < size and matrix[row + 1][col - 1] == '*':
- result += 1
- # up_right_corner row - 1, col + 1
- if 0 <= row - 1 < size and 0 <= col + 1 < size and matrix[row - 1][col + 1] == '*':
- result += 1
- # down_right_corner row + 1, col + 1
- if 0 <= row + 1 < size and 0 <= col + 1 < size and matrix[row + 1][col + 1] == '*':
- result += 1
- return result
- for i in range(size):
- for j in range(size):
- if matrix[i][j] == '*':
- continue
- matrix[i][j] = check_around(size, i, j)
- for i in matrix:
- print(*i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement