Rhyming Slang
시간 제한: 2000ms메모리 제한: 512MB출처: UKIEPC 2016BOJ 13527
문제
Rhyming slang involves replacing a common word with a phrase of two or three words, the last of which rhymes with the original word. For example,
- replacing the word “stairs” with the rhyming phrase “apples and pears”,
- or replacing “rotten” with the phrase “bales of cotton”.
English has such a wide variety of spellings and pronunciations that for any non-native speaker telling what rhymes isn’t always easy. Perhaps you can help?
Typically, two words rhyme (or can be forced to rhyme) if both of their endings can be found on the same list of word endings that sound the same.
Given a common word, a number of lists, each containing word endings that sound the same, and a number of phrases, determine if those phrases could be rhyming slang.
입력
- One line containing the single common word S (1 ≤ |S| ≤ 20).
- One line containing an integer E (1 ≤ E ≤ 10), the number of lists of word endings that sound the same.
- E lines, each no more than 100 characters long. Each a list of space-separated word endings.
- One line containing an integer P (1 ≤ P ≤ 10), the number of phrases to test.
- P lines, each no more than 100 characters long, containing a phrase pi of two or three words that might rhyme with the common word.
All words and letters will be in lower case. The common word’s ending will appear in at least one ending list.
출력
- P lines, each consisting of either:
- ’YES’: The phrase pi rhymes with the common word.
- ’NO’: The phrase pi does not rhyme with the common word.
예제
예제 1
입력
stairs 2 erres airs ears ares aires eet eat 2 apples and pears plates of meat
출력
YES NO
예제 2
입력
drought 2 aught ought aut acht ought oubt outte out oute 5 tasty sprout difficult route worried and fraught forever in doubt apples and pears
출력
YES YES YES YES NO
예제 3
입력
listen 1 issen isten ison 2 glisten listen
출력
YES YES
코드를 제출하려면 로그인하세요.