screenshot that the codes work. also, this is the only test cases
provided to us so there's nothing i can do about it.
here is my code that i submitted but it was an error in
OJ
i will give you an UPVOTE if you answered CORRECTLY and your
CODE works. thanks
Problem Statement Given a m by n grid of letters, (1 <m,n <50), and a list of words, find the location in the grid at which the word can be found. A word matches a straight, uninterrupted line of letters in the grid. A word can match the letters in the grid regardless of case (i.e. upper and lower case letters are to be treated as the same). The matching can be done in any of the eight directions either horizontally, vertically or diagonally through the grid. Input The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs. The input begins with a pair of integers, m followed by n, 1 m,n < 50 in decimal notation on a single line. The next m lines contain n letters each; this is the grid of letters in which the words of the list must be found. The letters in the grid may be in upper or lower case. Following the grid of letters, another integer k appears on a line by itself (1 <k <20). The next k lines of input contain the list of words to search for, one word per line. These words may contain upper and lower case letters only (no spaces, hyphens or other non-alphabetic characters) Sample Input #1 2 Copy 8 11 abcDEFGhige hebkwalbork FtyAwaldoRm FtsimrLqsrc byoArBeDeyv Klcbqwikonk strEBGadhrb yuiqlxcnBjf 4 Waldorf Bambi Betty Dagbert 98 jajPjpvd WJVhyowL YZMZEDG rxpMiqco RKGC zlmG KRjRKZKR DIM) FOmy dcAhazy UOLWUKMH 4 0 Oaw au Output For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line. a For each word in the word list, a pair of intecers representing the location of the corresponding word in the grid must be outputted. The integers must be separated by a single space. The first integer is the line in the grid where the first letter of the given word can be found (1 represents the topmost line in the grid, and m represents the bottommost line). The second integer is the column in the grid where the first letter of the given word can be found (1 represents the leftmost column in the grid, and n represents the rightmost column in the grid). If a word can be found more than once in the grid, then the location which is output should correspond to the uppermost occurence of the word (.e. the occurence which places the first letter of the word closest to the top of the grid). If two or more words are uppermost the output should correspond to the leftmost of these occurences. All words can be found at least once in the grid. . Sample Output #1 Copy 25 2 3 1 2 78 7 8 36 85 NOTE: USE PYTHON IN ENCODING. PROVIDE A SCREENSHOT THAT THE CODE WORKS. THANKS!
def isValid(i,,m,n, visited): return i >= @ and i<m and j >= 0 and j<n and visited[j] == False def search(board, visited,1,1, m, n, word, pos): moves = [[1,2],[0,1],[-1,0],[0,-1],[1,1],[1,-1], [-1,1],[-1,-1]] if pos -- len(word) return True for x,y in moves: if isvalid(i + x,j + y, m, n, visited) and board[i + x][j + y).lower() == word[pos]. lower(): visited[i + x][j + y] = True if search(board, visited, i + x, j + y,m,n,word,pos + 1): return True visited[i + x][j + y] = False return false t = int(input) for test in range(t): m, n = map(int, input().split() board = for i in range(m): board.append(list(input())) 4 = int(input) words = [] for i in range(a): words.append(input) for word in words: found - False for i in range(m): for j in range(n): if board[j].lower() == word[@].lower(): visited = [[False for j in range(n)] for i in range(m)] visited[j] = True if search(board, visited,i,j,m,n, word, 1): print(i + 1,j + 1) found = True break if found: break if not found: print(-1,-1) print()
Execution Results ********** Test case #1: IR (ValueError) [0.027s 10.13 MB] (0/10) Test case #2: IR (ValueError) [0.027s 10.13 MB] (0/10) Test case #3: IR (ValueError) [0.026s 10.13 MB] (0/10) Test case #4: IR (ValueError) [0.025s 10.13 MB] (0/10) Test case #5: IR (ValueError) [0.025s 10.13 MB] (0/10) Test case #6: IR (ValueError) (0.025s 10.13 MB] (0/10) Test case #7: IR (ValueError) [0.025s 10.13 MB] (0/10) Test case #8: IR (ValueError) [0.025s 10.13 MB] (0/10) Test case #9: IR (ValueError) [0.025s 10.13 MB] 0/10) Test case #10: IR (ValueError) [0.032s 10.13 MB] (0/10) Resources: 0.261s 10.13 MB Final score: 0/100 (0.0/100 points)