#C14116. Word Frequency Counter
Word Frequency Counter
Word Frequency Counter
You are given a text input via standard input. Your task is to count the frequency of each unique word present in the input. To do so, you must:
- Convert all letters to lowercase.
- Remove all punctuation.
- Discard common stop words. (The stop words are defined as: \(\{and, the, is, in, at, of, a, to, it, for, on, with, as, by, an, be, this, or, from, that\}\))
- Tokenize the input by whitespace.
- Count the frequency \(f_i\) for each remaining word \(w_i\).
- Output the top 10 most frequent words in descending order of frequency. If two words have the same frequency, sort them in lexicographical order.
If the input is empty, output nothing.
Note: The formula for the frequency of a word \(w_i\) is given by:
\[ f_i = \text{number of occurrences of } w_i \]inputFormat
The input is provided via standard input (stdin) as a text block. The text may span multiple lines and can include punctuation.
outputFormat
Print the top 10 most frequent words along with their counts, each on a separate line in the format:
word: count
If there are fewer than 10 words after processing, print all of them. If the input is empty, produce no output.
## samplePython is a programming language. Python is fun! A lot of people love coding in Python. The Python program is simple.
python: 4
programming: 1
language: 1
fun: 1
lot: 1
people: 1
love: 1
coding: 1
program: 1
simple: 1
</p>