Given a Morse table and a dictionary, match each gapless Morse code word to its dictionary word or report the first missing one.
Easy3Hash mapStringInterviewNo attempts yetTime limit1sMemory limit256 MBThe code that Samuel Morse built was first used as a way for two operators to send each other long and short electrical pulses. Those pulses moved an armature driven by an electromagnet. The length of a pulse and the length of the silence between pulses settled into what is now called Morse code.
Each letter is written as a run of dots and dashes. The international distress call SOS is ... --- ... (S is ... and O is ---). Letters are normally separated by a long pause, and without those pauses the code cannot be read back.
ACM is .- -.-. -- in Morse code and ANY is .- -. -.--. Remove the gaps between the letters and both words become .--.-.--, so the two can no longer be told apart.
The first 26 lines each contain one uppercase letter, a single space, and the Morse code for that letter. The letters come in alphabetical order, and the codes are the standard Morse codes, the same in every input.
The next line contains the number of dictionary words N (1≤N≤100). Each of the following N lines contains one word of 1 to 100 uppercase letters.
One or more test cases follow the dictionary. Each test case starts with a line holding the number of code words W (1≤W≤100), and a line holding 0 marks the end of the input. Each of the following W lines contains one code word, written in Morse code with no gaps between the letters. Every code word holds 1 to 400 symbols, each of them . or -. If a code word matches a dictionary word, it matches exactly one dictionary word.
Print the following for each test case. If every code word is found in the dictionary, print the matching words in order on one line, separated by single spaces. If any code word is missing from the dictionary, print only the first such code word, followed by a single space and not in dictionary., and print none of the matching words.