-
Notifications
You must be signed in to change notification settings - Fork 18
/
there_is_no_spoon1.py
42 lines (33 loc) · 1.21 KB
/
there_is_no_spoon1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from typing import List
if __name__ == "__main__":
EMPTY = "."
NODE = "0"
grid: List[str] = []
width = int(input()) # the number of cells on the X axis
height = int(input()) # the number of cells on the Y axis
for _ in range(height):
grid.append(input())
for y in range(height):
for x in range(width):
if grid[y][x] == NODE:
# node
output = f"{x} {y} "
# right neighbor
neighbor = EMPTY
for neighbor_x in range(x + 1, width):
neighbor = grid[y][neighbor_x]
if neighbor == NODE:
output += f"{neighbor_x} {y} "
break
if neighbor == EMPTY:
output += "-1 -1 "
# bottom neighbor
neighbor = EMPTY
for neighbor_y in range(y + 1, height):
neighbor = grid[neighbor_y][x]
if neighbor == NODE:
output += f"{x} {neighbor_y} "
break
if neighbor == EMPTY:
output += "-1 -1 "
print(output)