-
Notifications
You must be signed in to change notification settings - Fork 84
/
Grid and phrase.py
45 lines (36 loc) · 1.28 KB
/
Grid and phrase.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
n,m = map(int,input().split())
matrix = []
for i in range(n):
a= list(input())
matrix.append(a)
c=0
#horizontal
for i in range(n):
for j in range(m):
if m-j>=4:
#print(m,j,i)
if matrix[i][j]=='s' and matrix[i][j+1]=='a' and matrix[i][j+2]=='b' and matrix[i][j+3]=='a':
#print("yes")
c+=1
#Vertical
for j in range(m):
#ro
for i in range(n):
if n-i>=4:
if matrix[i][j]=='s' and matrix[i+1][j]=='a' and matrix[i+2][j]=='b' and matrix[i+3][j]=='a':
c+=1
for i in range(n):
for j in range(m):
if n-i>=4 and m-j>=4:
#print(i,j)
#print(matrix[i][j], matrix[i+1][j+1], matrix[i+2][j+2], matrix[i+3][j+3])
if matrix[i][j]=='s' and matrix[i+1][j+1]=='a' and matrix[i+2][j+2]=='b' and matrix[i+3][j+3]=='a':
#print("yes")
c+=1
for i in range(n-1,0,-1):
for j in range(m):
if i+1 >= 4 and m-j>=4:
if matrix[i][j]=='s' and matrix[i-1][j+1]=='a' and matrix[i-2][j+2]=='b' and matrix[i-3][j+3]=='a':
#print("ds")
c+=1
print(c)