시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB22151571.429%

문제

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

예제 출력 1

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

예제 출력 2

YES
YES
YES
YES
NO

예제 입력 3

listen
1
issen isten ison
2
glisten
listen

예제 출력 3

YES
YES

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > The UK & Ireland Programming Contest > UKIEPC 2016 H번

  • 문제를 만든 사람: Jim Grimmett