#C13961. Word Frequency Count

    ID: 43557 Type: Default 1000ms 256MiB

Word Frequency Count

Word Frequency Count

Given multiple lines of text input, count the occurrences of each word while ignoring case and punctuation. Words are defined as contiguous sequences of alphanumeric characters. The output should list each distinct word along with its frequency, with the words sorted in lexicographical (alphabetical) order. That is, if ( w_1, w_2, \ldots, w_k ) are the distinct words after processing, then for each word output a line of the form "word count", where count is the number of times the word appears. For example, for input lines "Hello, world!" and "Hello. How are you?", the word ( hello ) appears twice and the others once each.

inputFormat

The first line of input contains an integer ( n ) indicating the number of following lines. Each of the next ( n ) lines contains a string. These strings may include punctuation and mixed cases.

outputFormat

Output each distinct word and its frequency count on a separate line, in lexicographical order. Each line should contain the word and the count separated by a space.## sample

2
Hello, world!
Hello. How are you?
are 1

hello 2 how 1 world 1 you 1

</p>