-->
当前位置:首页 > 题库

PROGRAMMING:word frequency count

Luz5年前 (2021-05-10)题库440
Please write a program to count the number of all the different words in an English text, as well as the top 10% of the most frequent words.
The so-called "word" refers to a continuous string composed of no more than 80 words and characters, but words with a length of more than 15 will only be intercepted to retain the first 15 words and characters. The legal "word characters" are uppercase and lowercase letters, numbers and underscores. Other characters are considered as word separators.
###Input format:
Input to give a piece of non empty text, and end with the symbol #. Input to ensure that there are at least 10 different words.
###Output format:
Output the number of all the different words in the text in the first line. Note that "word" is not case sensitive. For example, "pat" and "pat" are considered to be the same word.
Then, according to the descending order of word frequency, the top 10% words with the largest word frequency are output according to the format of word frequency: word. If there are parallels, the output will be in ascending dictionary order.
###Input example:
```in
This is a test.
The word "this" is the word with the highest frequency.
Longlonglonglongword should be cut off, so is considered as the same as longlonglonglonee. But this_ 8 is different than this, and this, and this...#
this line should be ignored.
```
###Output example: (Note: Although the word 'the' also appears four times, we only need to output the first 10% (i.e. the first two of the 23 words) words, and according to the alphabetic order, 'the' ranks third, so we do not output them.)
```out
twenty-three
5:this
4:is
```
###Thanks to Mr. Guo Xiaobing of Wuhan University of technology for correcting the test data< br>





answer:If there is no answer, please comment