#C198. Autocomplete Tag Suggestions
Autocomplete Tag Suggestions
Autocomplete Tag Suggestions
You are given a partial tag string and a list of available tags. Your task is to output the top k suggestions from the list which start with the given partial tag. The search should be case-insensitive. The resulting suggestions must be sorted in lexicographical order based on their original values.
For example, if the partial tag is py
and the available tags are python
, pyramid
, pytest
, java
, and pyjava
, then the output should be the first 2 suggestions in sorted order among the tags that match the prefix.
Note: The input is provided through stdin
and the output must be printed to stdout
.
The lexicographical order is defined by the standard ASCII ordering. All comparisons for filtering must be done in a case-insensitive manner.
inputFormat
The input consists of multiple lines:
- The first line contains the partial tag string.
- The second line contains an integer k, the maximum number of suggestions to output.
- The third line contains an integer n, the number of available tags.
- The next n lines each contain one tag.
For example:
py 2 5 python pyramid pytest java pyjava
outputFormat
Print a single line containing the top k autocomplete suggestions that match the given partial tag, separated by single spaces. If fewer than k suggestions are available, print all of them.
The suggestions should be sorted lexicographically.
## sample
3
5
python
pyramid
pytest
java
pyjava
java pyjava pyramid