#C13338. Top 10 Word Frequency
Top 10 Word Frequency
Top 10 Word Frequency
You are given a block of text (which may span multiple lines) via standard input. Your task is to process the text by removing all punctuation, converting all letters to lowercase, and then counting the frequency of each word. Finally, display the top 10 most frequent words in descending order by their frequency. In the case of a tie, the word with the lexicographically smaller order should appear first. Each output line must contain the word and its frequency separated by a single space.
Note: If the text contains fewer than 10 distinct words, output all of them.
The solution must read from standard input (stdin) and output to standard output (stdout).
inputFormat
The input is provided via standard input and consists of one or more lines of text. The text may include letters, digits, whitespace, and punctuation.
outputFormat
The output should contain several lines. Each line must have a word followed by its frequency, separated by a single space. The words are listed in descending order by frequency, with ties broken in lexicographical order. Only the top 10 words (or all if there are fewer than 10) are output.
## sampleHello, hello! How are you? Are you there? Hello!!
hello 3
are 2
you 2
how 1
there 1
</p>