#C14208. Autocomplete Suggestions

    ID: 43832 Type: Default 1000ms 256MiB

Autocomplete Suggestions

Autocomplete Suggestions

Given a list of possible autocomplete words and a prefix string, your task is to output all completions that start with the given prefix. The matching should be case-insensitive and the results should be sorted in case-insensitive alphabetical order.

Formally, if the list of completions is \(\mathcal{C}\) and the prefix is \(p\), you are to output the list \(\{ c \in \mathcal{C} : \text{lower}(c) \text{ starts with } \text{lower}(p) \}\) sorted by their lowercase representation. If no completions match, output nothing.

For example, given completions ["Dog", "deer", "Deal", "cat", "cattle", "door"] and the prefix "do", the valid output is:

Dog
door

inputFormat

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

n
word1
word2
... 
wordn
prefix

where:

  • \(n\) is a positive integer representing the number of completion words.
  • Each of the following \(n\) lines contains a word.
  • The last line contains the prefix string (which can be empty).

outputFormat

Print each matching word on a separate line in case-insensitive alphabetical order. If there are no matches, do not print anything.

## sample
6
Dog
deer
Deal
cat
cattle
door
do
Dog

door

</p>