#K63017. Word Frequency Counter
Word Frequency Counter
Word Frequency Counter
Problem Statement: Given a text string, count the frequency of each unique word. In the text, remove all punctuation and special characters, convert all letters to lowercase, and consider any contiguous sequence of alphanumeric characters as a word. The output should list each distinct word along with its frequency, one pair per line, with the words sorted in alphabetical order.
Details: Let the input string be denoted by \(S\). First, remove all characters that are not letters (\(a\)–\(z\), \(A\)–\(Z\)), digits (\(0\)–\(9\)) or whitespace. Convert \(S\) to lowercase. Then, split \(S\) into words based on whitespace. Finally, for each unique word, count its frequency. Print each word and its frequency separated by a space, with one word-frequency pair per line. The words must be printed in alphabetical order.
inputFormat
Input Format: The input is given via standard input (stdin) as a single text string which may contain letters, digits, spaces, punctuation, and special characters. The entire input should be read (possibly spanning multiple lines) and processed as one string.
outputFormat
Output Format: For each distinct word in the processed text, output a line containing the word followed by a space and then its frequency. The lines must be sorted in alphabetical order of the words.
## sampleI am excited to try this new text analysis tool, aren't you excited too?
analysis 1
am 1
arent 1
excited 2
i 1
new 1
text 1
this 1
to 1
tool 1
try 1
too 1
you 1
</p>