#C4298. Most Frequent Words

    ID: 47820 Type: Default 1000ms 256MiB

Most Frequent Words

Most Frequent Words

Given a string of text, your task is to determine the three most frequent words in the text along with their frequencies. The words are considered case-insensitive and all punctuation marks are ignored. If the text contains fewer than three unique words, output all of them. In case there are no valid words in the input, produce no output.

The frequency of a word is defined as the number of times it appears in the text. Words with the same frequency should appear in the order of their first appearance in the text. For example, given the text:

Hello world! This is a test. This test is only a test.

the word "test" appears 3 times, while "this" and "is" each appear 2 times, so the output should be:

test: 3
this: 2
is: 2

Note: All formulas used are in LaTeX format if necessary. For example, frequency is defined as \(f(word)\). No extra explanation of algorithms is needed.

inputFormat

The input is provided from standard input (stdin) and consists of a single text string. The text may contain multiple punctuation marks and various cases. It can span multiple lines as well.

outputFormat

Output to standard output (stdout) the top three most frequent words (or all if fewer than three unique words) in descending order of frequency. Each line should be in the format word: count. If no valid word exists in the input, output nothing.

## sample
Hello world! This is a test. This test is only a test.
test: 3

this: 2 is: 2

</p>