#C12669. Word Frequency Counter

    ID: 42121 Type: Default 1000ms 256MiB

Word Frequency Counter

Word Frequency Counter

Your task is to write a program that reads text from standard input and counts the frequency of each word. The program should ignore punctuation and be case-insensitive. The words are defined as contiguous sequences of alphanumeric characters (i.e. matching the regular expression \b\w+\b). Once counted, the output should display each distinct word along with its frequency, sorted primarily by descending frequency and secondarily by ascending lexicographical order.

Formally, if a word w appears f(w) times, you should sort all words so that for any two words w1 and w2, either

[ f(w_{1}) > f(w_{2}) ]

or

[ f(w_{1}) = f(w_{2}) \quad \text{and} \quad w_{1} < w_{2}. ]

The output format must have one word and its count per line, separated by a single space.

inputFormat

The input consists of one or more lines of text provided via standard input. The input may contain punctuation and mixed case letters. The end of input is indicated by EOF.

outputFormat

For each unique word found in the input, print a line containing the word followed by a space and its frequency. The output should be sorted by descending frequency, and words with the same frequency should be sorted in lexicographical (alphabetical) order.

## sample
Hello world! This is a test. This test is only a test.\nHello again; testing, one, two, three.
test 3\na 2\nhello 2\nis 2\nthis 2\nagain 1\none 1\nthree 1\ntesting 1\ntwo 1\nworld 1