#C14538. Common Words Counter
Common Words Counter
Common Words Counter
You are given a text input from standard input. Your task is to process the text by removing all punctuation and converting all letters to lowercase. Then, count the frequency of each word, and output the top 10 most frequent words with their respective counts.
The output should consist of one word per line, followed by its frequency, separated by a single space. If the text contains fewer than 10 distinct words, output all of them.
Note: In case of a tie in frequency, the words should appear in the order of their first occurrence in the input.
For mathematical formulation, the frequency of a word \(w\) can be defined as:
$$ count(w)=\sum_{i=1}^{n} I(w=word_i) $$inputFormat
The input consists of one or more lines of text. The entire text should be read until EOF (end-of-file).
outputFormat
Output the top 10 most frequent words. Each line of the output should contain a word and its count separated by a space.
## sampleHello, hello! How are you? Hello, I am fine. How about you? I am good too.
hello 3
how 2
you 2
i 2
am 2
are 1
fine 1
about 1
good 1
too 1
</p>