Work-Study Student
InterviewTime limit1sMemory limit1024 MB
For each sentence, output the meanings of dictionary words that start at each position, using the dictionary-smallest word on ties, or -1 if nothing matches.
- Level
Easy3 of 10
- Topics
- Hash map, String, Implementation
- Solved
- No attempts yet
Problem
Haru became a work-study student whose job was to build a program that finds English words in a sentence and reports their meanings.
Haru never got around to writing the program. One day before the deadline, Haru asked you to help quickly. Please help Haru.
- Each entry is a pair , where is an English word and is its meaning.
- Given entries and sentences, the program answers each sentence as follows.
- Let the leftmost character of sentence be at position , and the rightmost at position . Here is the length of .
- The program reads each sentence from the first character to the last, in the order .
- While reading, if the characters at positions , joined in order, can form starting at position , the program must answer with . If several can be formed at position , the program answers with the of the that comes first in dictionary order.
- One sentence may require several answers.
For example, with the entries (ABC, X), (A, Y), and (CDE, Z) and the sentence ABCDE, the program must answer YXZ.
Input
The first line contains two integers and , the number of entries and the number of sentences, separated by a space. (; )
From the second line, the next lines each contain and , separated by a space. (; if , then )
The following lines each contain a string . ()
All input strings consist only of uppercase English letters and contain no spaces.
Output
For each string , print the string that the program must answer, one per line.
If the program has no answer for a string, print -1 instead.