#K4941. Word Frequency Counter
Word Frequency Counter
Word Frequency Counter
You are given a sentence. Your task is to count the number of occurrences of each unique word in the sentence. The counting should be case-insensitive and ignore punctuation.
Specifically, any punctuation marks such as commas (,), periods (.), exclamation points (!), and question marks (?) should be removed from the sentence prior to counting.
The words in the final output must be printed in lexicographical order (i.e., dictionary order) with each word and its count on a separate line, separated by a space.
Note: If the input string is empty or only contains punctuation, the output should be empty.
The problem can be mathematically stated as: Given a sentence \( S \), compute a function \( f: W \rightarrow \mathbb{N} \) where \( W \) is the set of unique words in \( S \) after processing (i.e. lowercasing and removing punctuation), and \( f(w) \) is the number of occurrences of \( w \) in \( S \).
inputFormat
The input consists of a single string which may span multiple lines. This string represents the sentence from which you have to count the occurrences of each word.
Input is provided via standard input (stdin).
outputFormat
For each unique word in the processed sentence, output a single line containing the word and its count separated by a space. The words should be printed in lexicographical order.
Output should be written to standard output (stdout). If there are no words to process, no output should be produced.
## sampleHello
hello 1
</p>