Advertisement
Bad_Programist

Untitled

Dec 7th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. def printpretty(x):
  2.     for row in x:
  3.         print(' '.join(row))
  4. def summ_mines(i, j, arr):
  5.     summ = 0
  6.     for x in range(i - 1, i + 2):
  7.         for y in range(j - 1, j + 2):
  8.             if x == -1 or x == len(arr) or y == -1 or y == len(arr[x]):
  9.                 continue
  10.             if arr[x][y] == '*':
  11.                 summ += 1
  12.     return summ
  13.                
  14. inp = input().split()
  15. strings = int(inp[0])
  16. vert = int(inp[1])
  17. num_mines = int(inp[2])
  18. summ = 0
  19. mines = []
  20. for i in range(num_mines):
  21.     mines.append(input().split())
  22. mines = [list(map(int, i)) for i in mines]
  23. res = [['*' if mines.count([i + 1, j + 1]) == 1 else '.' for j in range(vert)] for i in range(strings)]
  24. for i in range(strings):
  25.     for j in range(vert):
  26.         if mines.count([i + 1, j + 1]) == 1:
  27.             res[i][j] == '*'
  28.         else: res[i][j] == '.'
  29. for i in range(strings):
  30.     for j in range(vert):
  31.         if res[i][j] != '*':
  32.             res[i][j] = str(summ_mines(i, j, res))
  33. printpretty(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement