#C12306. Word Occurrence Counter
Word Occurrence Counter
Word Occurrence Counter
You are given a block of text (which may span multiple lines). Your task is to count the occurrence of each word in the text. Words are defined as sequences of alphanumeric characters (letters and digits). When counting words, you must ignore case, punctuation, and extra whitespace.
To process the text, convert it to lowercase and remove all punctuation. For instance, you may use the following LaTeX formula to represent the punctuation removal process:
\( text = \text{re.sub}(r'[^\w\s]', '', text) \)
After processing, output each distinct word along with its frequency. The output should list the words in lexicographical (alphabetical) order, each on a new line with the word and its count separated by a space.
inputFormat
The input consists of a block of text provided via standard input (stdin). The text may span multiple lines. An empty input means there are no words.
outputFormat
For each unique word in the text, output a line with two elements: the word and its frequency count, separated by a space. The words must be output in lexicographical order.
## sampleHello world! World hello.
hello 2
world 2
</p>