-
Notifications
You must be signed in to change notification settings - Fork 222
/
Copy pathcavity-map.py
32 lines (25 loc) · 861 Bytes
/
cavity-map.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
#!/bin/python3
import sys
def cavityMap(grid):
leng = len(grid)
output = [[0]*leng for _ in range(leng)]
for ind in range(leng):
for jnd in range(leng):
if (0 < ind < leng-1 and 0 < jnd < leng-1 and
grid[ind][jnd] > grid[ind+1][jnd] and
grid[ind][jnd] > grid[ind-1][jnd] and
grid[ind][jnd] > grid[ind][jnd+1] and
grid[ind][jnd] > grid[ind][jnd-1]):
output[ind][jnd] = 'X'
else:
output[ind][jnd] = grid[ind][jnd]
return output
if __name__ == "__main__":
n = int(input().strip())
grid = []
grid_i = 0
for grid_i in range(n):
grid_t = list(map(int, input().strip()))
grid.append(grid_t)
result = cavityMap(grid)
print("\n".join(["".join(map(str, x)) for x in result]))