#C1092. Word Frequency Counter
Word Frequency Counter
Word Frequency Counter
Given a single line of text, your task is to count the frequency of each distinct word and then display the result in the following order:
- Words with lower frequency come first.
- If two words have the same frequency, sort them in alphabetical order.
Each output line should follow the format word: frequency
. For example, if the input is "hello world hello", the output should be:
world: 1 hello: 2
Please note that the input will be provided via standard input (stdin) and the output should be printed to standard output (stdout).
inputFormat
The input consists of a single line of text containing words separated by whitespace.
You may assume that the entire input is contained in this single line.
outputFormat
Output the frequency of each word on separate lines following the format word: frequency
. The words must be sorted primarily by their frequency (in ascending order), and secondarily in alphabetical order if frequencies are equal.
hello
hello: 1
</p>