-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex_matrix_parcours_check_start.py
50 lines (43 loc) · 1.59 KB
/
ex_matrix_parcours_check_start.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
43
44
45
46
47
48
49
50
#*******
#* Read input from STDIN
#* Use echo or print to output your result, use the /n constant at the end of each result line.
#* Use:
#* local_print (variable );
#* to display simple variables in a dedicated area.
#* ***/
import sys
lines = []
for line in sys.stdin:
lines.append(line.rstrip('\n'))
lines = lines[1:]
u = set()
c = 0
for i in range(len(lines)):
l = lines[i]
for j in range(len(l)):
if l[j] == "X":
if j > 0 and l[j-1] != "X" and (i, j-1) not in u:
u.add((i, j-1))
c +=1
if j < len(l) -1 and l[j+1] != "X" and (i, j+1) not in u:
u.add((i, j+1))
c +=1
if i > 0 and lines[i-1][j] != "X" and (i-1, j) not in u:
u.add((i-1, j))
c +=1
if i < len(l) -1 and lines[i+1][j] != "X" and (i+1, j) not in u:
u.add((i+1, j))
c +=1
if i < len(l) -1 and j < len(l) - 1 and lines[i+1][j+1] != "X" and (i+1, j+1) not in u:
u.add((i+1, j+1))
c +=1
if i > 0 and j < len(l) - 1 and lines[i-1][j+1] != "X" and (i-1, j+1) not in u:
u.add((i-1, j+1))
c +=1
if i < len(l) -1 and j > 0 and lines[i+1][j-1] != "X" and (i+1, j-1) not in u:
u.add((i+1, j-1))
c +=1
if i >0 and j >0 and lines[i-1][j-1] != "X" and (i-1, j-1) not in u:
u.add((i-1, j-1))
c +=1
print(c)