#C13546. Word Frequency Counter

    ID: 43096 Type: Default 1000ms 256MiB

Word Frequency Counter

Word Frequency Counter

You are given a series of text lines. Your task is to count the frequency of each unique word while ignoring case and punctuation. For the purpose of this problem, a word is defined as any consecutive sequence of alphanumeric characters. In other words, if the input text is given as:

n
line_1
line_2
... 
line_n

then you are to compute for each word \(w\) its frequency according to the formula \[ f(w)=\sum_{i=1}^{n} I(w_i=w), \] where \(I(\cdot)\) is the indicator function.

The output should list each unique word (in lexicographical order) followed by its frequency, separated by a single space on a new line.

inputFormat

The first line contains an integer \(n\) representing the number of text lines. The following \(n\) lines each contains a string which may include letters, digits, spaces, and punctuation.

Sample Input:
2
Hello world!
World, hello.

outputFormat

For each unique word, output the word and its corresponding frequency count in alphabetical order. Each output line should contain the word followed by a single space and the frequency.

Sample Output:
hello 2
world 2
## sample
1
Hello world!
hello 1

world 1

</p>