#K80642. Auto-Complete Suggestions
Auto-Complete Suggestions
Auto-Complete Suggestions
You are given a log of phrases along with their frequency counts. Your task is to implement an auto-completion feature which, given a prefix string \( p \), suggests at most 3 phrases from the log that start with \( p \). The suggestions must be sorted primarily in descending order by their frequency. If there is a tie (i.e., two phrases have the same frequency), they should be sorted in ascending lexicographical order.
If no phrase in the log starts with the given prefix, output No suggestions.
Note: Each input line for the log will contain a phrase and its frequency separated by a space. The phrase may include spaces.
inputFormat
The input is read from stdin and has the following format:
- The first line contains an integer \( n \), the number of log entries.
- The next \( n \) lines each contain a phrase (which may contain spaces) followed by an integer frequency. The phrase and the integer are separated by a space (the integer is guaranteed to be the last element in the line).
- The last line contains the prefix string \( p \) to search for.
outputFormat
Output the auto-complete suggestions to stdout. Each suggestion should be printed on a separate line in the format: phrase frequency
.
If there are less than 3 suggestions, output all of them; if there are no suggestions, output a single line containing No suggestions.
## sample5
hello 10
hi 5
how are you 3
howdy 7
house 8
ho
house 8
howdy 7
how are you 3
</p>