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

PROGRAMMING:Word frequency statistics - basic questions

Luz5年前 (2021-05-10)题库404
Please write a program to count the number of all different words in a piece of text (without symbols) and the top five words with the highest frequency.
###Input format:
Input to give a non empty text, which can be Chinese or English, separated by spaces or lines.
###Output format:
The top five words with the largest number and frequency of output words. Note that "pat" 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 five words with the largest word frequency are output in the format of "word: word frequency". If there are parallels, the output will be in ascending dictionary order.
###Input sample 1:
Here is a set of inputs. For example:
```in
This is a test
so is considered as the same as long
But this_ 8 is different than this
```
###Output sample 1:
The corresponding output is given here. For example:
```out
fourteen
is:3
as:2
this:2
a:1
but:1
```
###Input sample 2:
Here is a set of inputs. For example:
```in
Shuanger Hong Qigong Zhao Min Zhao Min Xiaoyao son worship Yin Tianzheng king of the Golden Wheel law Qiao Feng Yang Guo Jing
Yang Xiao pays homage to Yin Tianzheng, Duan Yu Yang Xiao Murong Fu a Zi Murong Fu Guo Fu Qiao Feng Ling Hu Chong Guo Fu
Yang Guoqiao Feng Yang Xiao Qiao Feng Murong Fu
```
###Output sample 2:
The corresponding output is given here. For example:
```out
seventeen
Qiao Feng: 4
Murong Fu: 3
Yang Xiao: 3
Yang Guo: 2
Yin Tianzheng: 2
```







answer:If there is no answer, please comment