#C929. Find Words With Prefix

    ID: 53366 Type: Default 1000ms 256MiB

Find Words With Prefix

Find Words With Prefix

Given a list of words and a prefix string, your task is to output all words that start with the given prefix. The problem can be formulated as follows:

Let \(W\) be the list of words and \(p\) be the prefix. You need to produce a filtered list \(L\) such that for every word \(w \in W\), \(w \in L\) if and only if \(w\) starts with \(p\). In mathematical terms, if the function startsWith is defined as \[ startsWith(w, p)=\begin{cases}1,&\text{if } w[0:|p|]=p,\\0,&\text{otherwise,}\end{cases} \] then \[ L = \{w \in W \mid startsWith(w,p)=1\}. \]

You should read input from standard input and write the result to standard output. If no word satisfies the condition, output an empty line.

inputFormat

The input is read from standard input and has the following format:

The first line contains an integer (n), representing the number of words. The next (n) lines each contain a single word. The last line contains the prefix string to be matched.

outputFormat

Output a single line containing all words that start with the given prefix, separated by a single space. If there is no matching word, output an empty line.## sample

5
apple
banana
apricot
avocado
berry
ap
apple apricot

</p>