#C9260. Autocomplete Search
Autocomplete Search
Autocomplete Search
You are given a list of words and a list of query prefixes. For each query prefix, output all the words from the list that start with that prefix in lexicographical order. If there is no word starting with the given prefix, output NULL
.
Input Format: The first line contains an integer N, the number of words. The second line contains N space-separated words. The third line contains an integer Q, the number of queries, followed by a line with Q space-separated query prefixes.
Output Format: For each query, output a line containing the matching words separated by a single space. If no words match, output NULL
.
Note: The filtering happens based on the prefix match. That is, for a query p and a word w, w is selected if and only if the following holds:
\[ w[0:|p|] = p \]
where \(|p|\) is the length of the prefix p.
inputFormat
The input is given from stdin in the following format:
N word1 word2 ... wordN Q query1 query2 ... queryQ
Where N is the number of words, followed by a line of N words, then Q representing the number of queries, followed by a line of Q query prefixes.
outputFormat
The output should be printed to stdout. For each query, print a line containing all words that start with the given query prefix in lexicographical order, separated by a single space. If no word matches the prefix, print NULL
.
5
apple app application bat batch
3
ap ba cat
app apple application
bat batch
NULL
</p>