#C13378. Word Frequency Counter
Word Frequency Counter
Word Frequency Counter
Given a sentence, count the frequency of each word by ignoring case and punctuation. Punctuation should be removed and all letters converted to lowercase before counting. Then, output each distinct word along with its frequency in lexicographical order.
Note: Words are defined as sequences of alphanumeric characters. If the input is empty, no output should be produced.
Mathematical representation: \( freq(w) = \text{number of occurrences of } w \) for each word \( w \) in the sentence.
inputFormat
The input consists of a single line which is a sentence. This sentence may contain letters, digits, spaces, and punctuation marks.
outputFormat
For each distinct word in the sentence, print a line with the word and its frequency separated by a space. The words must be sorted in lexicographical (alphabetical) order. If the input is empty, output nothing.
## sampleThis is a test. This is only a test.
a 2
is 2
only 1
test 2
this 2
</p>