Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- 1. search main_grid for first letter of first word to be searched
- 2. if match, check surrounding letters if second letter matches
- 3. if match again, continue checking if all letters in that direction match
- 4. if yes, output index of first letter. if no, search for next occurrence of letter and repeat from step 2
- 5. repeat for other words in words
- """
- R, C = map(int, input().split())
- print(R, C)
- main_grid = []
- results_a = []
- results_b = []
- for i in range(R):
- main_grid.append(input()) # grid to be searched
- N = int(input())
- words = []
- for i in range(N):
- words.append(input())
- print(words)
- print(words[0][2])
- dirs = [[-1,0],[1,0],[0,-1],[0,1],[-1,-1],[-1,1],[1,-1],[1,1]] # W, E, S, N, SW, NW, SE, NE
- i = 0
- while i < N:
- for x in range(R):
- for y in range(C):
- z = 0
- if main_grid[x][y] == words[i][z]: # searches all coords matching first letter of words[i]
- while z < len(words[i]):
- coords = 0
- while coords < 7:
- a,b = dirs[coords]
- x += a
- y += b
- print(x)
- print(y)
- if main_grid[x][y] == words[i][z]:
- z += 1
- elif main_grid[x][y] == words[i][len(words[i])-1]:
- results_a.append(x)
- results_b.append(y)
- else:
- break
- coords += 1
- print(results_a)
- print(results_b)
- i += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement