编写程序,读入以下英文段落,统计段落中每个单词重复出现的频率。报告段落中单词的个数(含重复单词),并按频率从高到低的次序输出频率在前5%的单词。
示例:
• 英文段落:
we assume that you want to learn quickly how to write useful c++ programs. therefore, we start by explaining the most useful parts of c++. this strategy may seem obvious when we put it that way, but it has the radical implication that we do not begin by teaching c, even though c++ builds on c. instead, we use high-level data structures from the start, explaining only later the foundations on which those data structures rest. this approach lets you to begin writing idiomatic c++ programs immediately.
注意:
(1) 单词末尾可能出现“,”和“.”的标点,统计词频时应当去掉该标点再判断该单词是否曾经出现。除这两种标点以外的其它标点符号可以暂不考虑。对于一个string类型的对象s,去掉它的最后一个字符可以采用s.erase(s.end()–1);
(2) 段落中所有单词已均为小写;
(3) 输出频率在前5%不意味着输出单词的个数为 [0.05 *单词总数] ,因为一些单词的出现频率可能持平。