Rhyming Slang
Time limit2sMemory limit512 MB
Given a word and lists of rhyming endings, decide for each phrase whether its last word shares a rhyming ending with the word.
- Level
Easy3 of 10
- Topics
- String, Hash map, Implementation
- Solved
- No attempts yet
Problem
Rhyming slang replaces a common word with a phrase of two or three words whose last word rhymes with the original word. For example:
- replace stairs with apples and pears,
- replace rotten with bales of cotton.
English spelling and pronunciation vary so much that a non-native speaker cannot always tell which words rhyme.
You are given several lists, each holding word endings that sound the same. Two words rhyme when one list holds an ending that is a suffix of the first word and an ending that is a suffix of the second word. The two endings do not have to be equal, but they must come from the same list.
Given a common word, the lists of endings, and several phrases, decide for each phrase whether it could be rhyming slang for that word.
Input
- The first line contains the common word ().
- The second line contains (), the number of lists of endings that sound the same.
- Each of the next lines contains one list, at most 100 characters long, holding endings separated by spaces.
- The next line contains (), the number of phrases to test.
- Each of the next lines contains one phrase , at most 100 characters long, made of one to three words separated by single spaces.
All letters are lower case. The ending of appears on at least one list.
Output
Print lines. On line print YES if the last word of phrase rhymes with , and NO otherwise.