1614: *出现次数最多的单词

Memory Limit:128 MB Time Limit:8.000 S
Judge Style:Text Compare Creator:
Submit:100 Solved:23

Description

    给定一个单词列表 words 和一个整数 k ,返回前 k 个出现次数最多的单词。 
    返回的答案应该按单词出现次数由高到低排序。如果不同的单词有相同出现次数, 按字典顺序 排序。

示例:
输入:it is to be or not to be that is a question 
            k=3 
输出:be is to 
解释:“is“ “to” 和 “be” 都出现两次
     -注意,输出按字母顺序为“be“ “is“ “to"。
          

Input

输入共二行,前一行为单词列表 words,每一单词间空一格,单词只有小写英文字母。 后一行为 k。 

Output

      输出为一行,为k个出现最多的单词,单词间空一格。如果不同的单词有相同出现次数, 按字典顺序排序。

Sample Input Copy

it is to be or not to be that is a question 
3

Sample Output Copy

be is to

HINT

 words 字母长度<=300,单词数<10^5; k<=10。单词只有小写字母。