Substring Set Membership
Time limit1sMemory limit256 MB
You receive a set of patterns and query strings and print YES for each query containing a pattern as a contiguous substring, NO otherwise.
- Level
Medium6 of 10
- Topics
- String matching, Trie
- Solved
- No attempts yet
Problem
The set has elements and every element is a string. Given strings, decide for each one whether any of its substrings belongs to . Print YES if at least one substring is in , and NO if none of them is. A substring here means a contiguous stretch of the string.
For example, take to be {"www", "woo", "jun"}. The string "myungwoo" has the substring "woo", which is in , so its answer is YES. The string "hongjun" has the substring "jun", which is in , so its answer is YES. The string "dooho" has no substring in , so its answer is NO.
Input
The first line has the size of the set . ()
Each of the next lines has one element of . No element is longer than characters.
The next line has , the number of strings to decide. ()
Each of the next lines has one string to decide. No such string is longer than characters.
Every string in the input consists of lowercase letters only.
Output
Print lines, one answer per input string, in the order the strings were given. Print YES if at least one substring of that string is in , and NO otherwise.