#C12859. Word Frequency Counter
Word Frequency Counter
Word Frequency Counter
You are given n sentences. Your task is to count the frequency of each unique word across all the sentences. Words are considered case-insensitive and any punctuation characters .,!?
should be ignored. In other words, a word is defined as a sequence of letters after converting all characters to lowercase and removing the punctuation mentioned.
The input begins with an integer \(n\) which denotes the number of sentences. The following \(n\) lines each contain a sentence. Your program should output the frequency count for each unique word in lexicographical order, with each line containing a word followed by its frequency.
Note: If no sentences are provided (i.e. \(n = 0\)), your program should produce no output.
inputFormat
The first line contains an integer \(n\), which is the number of sentences. Each of the next \(n\) lines contains a single sentence.
Input Example:
3 Hello world! Hello again, World. HELLO... world?
outputFormat
For each unique word, print a line containing the word and its frequency separated by a space. The words must be printed in lexicographical order (i.e. alphabetical order).
Output Example:
again 1 hello 3 world 3## sample
1
Hello world!
hello 1
world 1
</p>