#C12797. Predict Words by Prefix
Predict Words by Prefix
Predict Words by Prefix
You are given a list of words (the corpus) and a prefix string. Your task is to find all words in the corpus that start with the given prefix, ignoring case. The resulting words should be sorted in alphabetical order based on their lowercase representation. If the prefix is an empty string, simply sort the entire corpus in alphabetical order (again, case-insensitively). If no word matches the prefix, output nothing.
For example, if the input is:
6 apple application angle banana Appetizer apply app
Then the matching words (when compared in a case‐insensitive manner) are: Appetizer
, apple
, application
, and apply
. When sorted by their lowercase equivalents, the output is:
Appetizer apple application apply
inputFormat
The input is read from standard input (stdin) in the following format:
- The first line contains an integer n (n ≥ 0) representing the number of words in the corpus.
- The following n lines each contain one word.
- The last line contains the prefix string. The prefix can be empty.
outputFormat
Output the matching words sorted in alphabetical order (based on case-insensitive comparison). Each word should be printed on its own line. If no words match the prefix, output nothing.
## sample6
apple
application
angle
banana
Appetizer
apply
app
Appetizer
apple
application
apply
</p>