#C7086. Dictionary Prefix Autocomplete

    ID: 50918 Type: Default 1000ms 256MiB

Dictionary Prefix Autocomplete

Dictionary Prefix Autocomplete

In this problem, you are given a dictionary consisting of a list of words and a list of prefixes. For each prefix, you are required to output the words from the dictionary that start with that prefix. The order of the words output for each prefix should be the same as their order in the dictionary.

For example, if the dictionary is [
(\texttt{apple}), (\texttt{app}), (\texttt{application}), (\texttt{banana}), (\texttt{band}), (\texttt{bandana}), (\texttt{bandwidth}), (\texttt{cat}), (\texttt{catch}), (\texttt{cater})
] and the prefixes are [(\texttt{app}), (\texttt{ban}), (\texttt{cat}), (\texttt{zoo})], then the output will contain four lines with the words corresponding to each prefix.

inputFormat

The input is given via standard input (stdin) as follows:

  1. The first line contains an integer (n) representing the number of words in the dictionary.
  2. The second line contains (n) space-separated words representing the dictionary.
  3. The third line contains an integer (m) representing the number of prefixes.
  4. The fourth line contains (m) space-separated prefixes.

Note: If (n = 0), the second line will be empty. Similarly, if (m = 0), no prefixes will be provided.

outputFormat

For each prefix (in the order they are given), print a single line containing all the words from the dictionary that start with that prefix, separated by a single space. If no words match a given prefix, output an empty line for that prefix. The output is printed to standard output (stdout).## sample

10
apple app application banana band bandana bandwidth cat catch cater
4
app ban cat zoo
apple app application

banana band bandana bandwidth cat catch cater

</p>