Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.44 KB | None | 0 0
  1. n = int(input())
  2. a = []
  3. b = []
  4. is_null = True
  5. for row_index in range(n):
  6.     a.append(list(map(int, input().split())))
  7.     b.append(list(map(str, a[row_index])))
  8.     if any(a[row_index]):
  9.         is_null = False
  10. if not is_null:
  11.     for row_index, row in enumerate(a):
  12.         for col_index, value in enumerate(row):
  13.             if value > 0:
  14.                 continue
  15.             r = 1
  16.             while True:
  17.                 count = 0
  18.                 score = ''
  19.                 x = col_index - r
  20.                 y = row_index
  21.                 num = 0
  22.                 if x < 0:
  23.                     offset = abs(x)
  24.                     if row_index + x < 0:
  25.                         offset = r
  26.                     x += offset
  27.                     y -= offset
  28.                     num += offset
  29.                 while (num < r) and (y > -1):
  30.                     if a[y][x] > 0:
  31.                         count += 1
  32.                         score = str(a[y][x])
  33.                     if count > 1:
  34.                         break
  35.                     x += 1
  36.                     y -= 1
  37.                     num += 1
  38.                 if count > 1:
  39.                         break
  40.                 x = col_index
  41.                 y = row_index - r
  42.                 num = 0
  43.                 if y < 0:
  44.                     offset = r
  45.                     if col_index + abs(y) < n:
  46.                         offset = abs(y)
  47.                     x += offset
  48.                     y += offset
  49.                     num += offset
  50.                 while (num < r) and (x < n):
  51.                     if a[y][x] > 0:
  52.                         count += 1
  53.                         score = str(a[y][x])
  54.                     if count > 1:
  55.                         break
  56.                     x += 1
  57.                     y += 1
  58.                     num += 1
  59.                 if count > 1:
  60.                     break
  61.                 x = col_index + r
  62.                 y = row_index
  63.                 num = 0
  64.                 if x > n - 1:
  65.                     offset = r
  66.                     if row_index + (x - n + 1) < n:
  67.                         offset = x - n + 1
  68.                     x -= offset
  69.                     y += offset
  70.                     num += offset
  71.                 while (num < r) and (y < n):
  72.                     if a[y][x] > 0:
  73.                         count += 1
  74.                         score = str(a[y][x])
  75.                     if count > 1:
  76.                         break
  77.                     x -= 1
  78.                     y += 1
  79.                     num += 1
  80.                 if count > 1:
  81.                     break
  82.                 x = col_index
  83.                 y = row_index + r
  84.                 num = 0
  85.                 if y > n - 1:
  86.                     offset = r
  87.                     if col_index - (y - n + 1) > -1:
  88.                         offset = y - n + 1
  89.                     x -= offset
  90.                     y -= offset
  91.                     num += offset
  92.                 while (num < r) and (x > -1):
  93.                     if a[y][x] > 0:
  94.                         count += 1
  95.                         score = str(a[y][x])
  96.                     if count > 1:
  97.                         break
  98.                     x -= 1
  99.                     y -= 1
  100.                     num += 1
  101.                 if count > 0:
  102.                     if count == 1:
  103.                         b[row_index][col_index] = score
  104.                     break
  105.                 r += 1
  106. for row in b:
  107.     print(' '.join(row))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement