#C13321. Most Frequent Word
Most Frequent Word
Most Frequent Word
Given a string of text, your task is to determine the most frequently occurring word along with its frequency. In this problem, words are defined as contiguous sequences of alphanumeric characters. Ignore any punctuation and consider uppercase and lowercase letters as the same (i.e. normalization to lowercase is required).
If there is a tie in frequency, the word that appears first in the string should be selected. If no valid words are found (i.e. the input string is empty or contains only punctuation), output an empty string for the word and 0 as its frequency.
The answer should be printed in two lines using standard input and output: the first line for the word and the second line for its frequency. The word and frequency are separated by a newline.
For example, given the input:
Hello, hello HELLO! How are you, you, YOU!
the correct output is:
hello 3
In the above example, although "hello" and "you" both occur three times, "hello" appears first in the text.
The following formula shows the process:
\(\text{word} = \operatorname{argmax}_{w \in \mathcal{W}}\,\text{freq}(w)\)
\(\text{frequency} = \max_{w \in \mathcal{W}}\,\text{freq}(w)\)
inputFormat
The input consists of a single line which is a string of text. The string may contain letters, digits, spaces, and punctuation.
outputFormat
The output should consist of two lines. The first line contains the most frequent word (in lowercase). The second line contains its frequency as an integer.
## samplehello
hello
1
</p>