← 返回 cisco 的题目列表Word Search in Rows and Columns
类型:qbank
Given a letter grid and a list of words, return `Yes` or `No` for each word depending on whether it appears in a row or column, forward or backward.
Requirements
Input line 1 contains grid_row and grid_col.
The next grid lines contain space-separated characters.
The next line is word_size, the number of words to search.
The last line contains the K words.
Words may appear horizontally or vertically, forward or backward.
Diagonal words do not count.
Matching is case-sensitive.
Print K space-separated strings, each Yes if the corresponding word is present or No otherwise.
Examples
Input:
3 3
C A T
I D O
N O M
4
CAT TOM ADO MOM
Output:
Yes Yes Yes No
Explanation: CAT is in the first row, TOM is in the last column, ADO is in the middle column, and MOM is absent.
Notes
A simple implementation can build all row strings, reversed row strings, column strings, and reversed column strings, then test each word as a substring.