Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = int(input())
- a = []
- b = []
- is_null = True
- for row_index in range(n):
- a.append(list(map(int, input().split())))
- b.append(list(map(str, a[row_index])))
- if any(a[row_index]):
- is_null = False
- if not is_null:
- for row_index, row in enumerate(a):
- for col_index, value in enumerate(row):
- if value > 0:
- continue
- r = 1
- while True:
- count = 0
- score = ''
- x = col_index - r
- y = row_index
- num = 0
- if x < 0:
- offset = abs(x)
- if row_index + x < 0:
- offset = r
- x += offset
- y -= offset
- num += offset
- while (num < r) and (y > -1):
- if a[y][x] > 0:
- count += 1
- score = str(a[y][x])
- if count > 1:
- break
- x += 1
- y -= 1
- num += 1
- if count > 1:
- break
- x = col_index
- y = row_index - r
- num = 0
- if y < 0:
- offset = r
- if col_index + abs(y) < n:
- offset = abs(y)
- x += offset
- y += offset
- num += offset
- while (num < r) and (x < n):
- if a[y][x] > 0:
- count += 1
- score = str(a[y][x])
- if count > 1:
- break
- x += 1
- y += 1
- num += 1
- if count > 1:
- break
- x = col_index + r
- y = row_index
- num = 0
- if x > n - 1:
- offset = r
- if row_index + (x - n + 1) < n:
- offset = x - n + 1
- x -= offset
- y += offset
- num += offset
- while (num < r) and (y < n):
- if a[y][x] > 0:
- count += 1
- score = str(a[y][x])
- if count > 1:
- break
- x -= 1
- y += 1
- num += 1
- if count > 1:
- break
- x = col_index
- y = row_index + r
- num = 0
- if y > n - 1:
- offset = r
- if col_index - (y - n + 1) > -1:
- offset = y - n + 1
- x -= offset
- y -= offset
- num += offset
- while (num < r) and (x > -1):
- if a[y][x] > 0:
- count += 1
- score = str(a[y][x])
- if count > 1:
- break
- x -= 1
- y -= 1
- num += 1
- if count > 0:
- if count == 1:
- b[row_index][col_index] = score
- break
- r += 1
- for row in b:
- print(' '.join(row))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement