Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n, m = map(int, input().split()) # n x m field
- field = [[] for y in n] # 0 - dead 1 - active
- count_active = 0
- for i in range(n):
- for x in input().split():
- if x == 'X':
- count_active += 1
- field[i].append(1)
- else:
- field[i].append(0) # X - dead O - active
- def get_count(i, j, need, n, m, field):
- count = 0
- if i - 1 >= 0 and field[i - 1][j] == need:
- count += 1
- if j - 1 >= 0 and field[i][j - 1] == need:
- count += 1
- if i + 1 < n and field[i + 1][j] == need:
- count += 1
- if j + 1 < m and field[i][j + 1] == need:
- count += 1
- if i + 1 < n and j + 1 < m and field[i + 1][j + 1] == need:
- count += 1
- if i + 1 < n and j - 1 >= 0 and field[i + 1][j - 1] == need:
- count += 1
- if i - 1 >= 0 and j + 1 < m and field[i - 1][j + 1] == need:
- count += 1
- if i - 1 >= 0 and j - 1 >= 0 and field[i - 1][j - 1] == need:
- count += 1
- return count
- con = [] # i j k
- while count_active != 0:
- for x in con:
- if x[2] == 0:
- count_active -= 1
- field[x[0]][x[1]] = x[2]
- con = []
- for i in range(n):
- for j in range(m):
- if field[i][j] == 0:
- if get_count(i, j, 1, n, m, field) == 3:
- con.append([i, j, 1])
- if field[i][j] == 1:
- t = get_count(i, j, 1, n, m, field)
- if t >= 4 or t <= 1:
- con.append([i, j, 0])
- for line in field:
- for x in line:
- print('X' if x == 0 else 'O', end=' ')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement