#C13760. Word Frequency Counter
Word Frequency Counter
Word Frequency Counter
You are given a string of text. Your task is to count the frequency of each word in the text, ignoring punctuation and letter case. That is, all letters should be converted to lowercase, and punctuation should be removed before counting.
The word frequency count should be printed in alphabetical order, one entry per line in the format: word: count
.
For example, if the input is Hello World! Hello hello!
, then the output should be:
hello: 3 world: 1
Note: Words are defined as contiguous sequences of alphanumeric characters. You may use regular expressions or other methods to filter out punctuation. If the input string is empty, print nothing.
The formula for converting text can be summarized as:
\(\text{cleaned_text} = \text{lowercase}(\text{remove_punctuation}(text))\)
inputFormat
The input consists of a single line containing the text. The text may include letters, numbers, spaces, and punctuation.
outputFormat
For each unique word in the processed text, print a line in the format word: count
, where word
is in lowercase. The output should be ordered alphabetically by the word. If the input is empty, do not print anything.
Hello World
hello: 1
world: 1
</p>