Logo Universal Online Judge

UOJ

时间限制:1 s 空间限制:512 MB
Statistics

Word Count

题目描述

小 X 最近在忙着阅读英文文献, 但是文献内容实在是太多了, 小 X 想出去玩, 不想全文阅读. 于是小 X 来找你, 想请你写一段程序, 统计这段文献中出现次数最多的 n 个单词, 这样小 X 就可以只阅读这 n 个关键词, 当作小 X 已经读完了这段文献.

输入

1 行为一个正整数 n.

接下来的若干行给出一段文章. 文章中的单词以空格分隔, 最后以一个单独的符号 # 结尾.

输入保证存在至少 n 个不同的单词, 且保证除了结尾的 # 外, 文章中只有 a ~ z, A ~ Z 和空格, 每个单词的长度不超过 20 个字母, 仅有大小写差异的两个单词看作相同的单词.

测试点 1 输入:

10
A woman is pushing a cart of food across a plaza
A dog is grazing in a green grassy area next to a tree
A picture of a young boy from inside a plane
A couple of giraffe standing around an older model giraffe
A bus is stopped at a stop in front of a small apartment
A group of school buses are traveling down a busy city street
A sign sitting on the side of the road near grassy area
A passenger plane is in the midst of taking off
A man is sitting on a bench while reading while sitting on a bench
A red and yellow bus sitting on the side of the street
#

输出

输出共有 n 行, 按照单词的出现次数降序输出单词和出现次数. 若出现次数相同, 则按照字典序排序.

测试点 1 输出:

a 21
of 8
is 5
the 5
on 4
sitting 4
in 3
area 2
bench 2
bus 2

提示

  • 散列表 (Hash Table)
  • n <= 20
  • 所有单词数不多于 240000