#K74822. Case-Insensitive Word Count
Case-Insensitive Word Count
Case-Insensitive Word Count
Given a string of text, count the occurrences of each word regardless of their case (i.e. the comparison is case-insensitive). Each word is separated by whitespace. Your task is to output each distinct word along with its frequency. The results must be printed in lexicographical order, one word per line followed by a space and its count.
For instance, if the input is: The cat in the hat
, the output should be:
cat 1 hat 1 in 1 the 2
Note that the words are converted to lowercase before counting. A formula to represent the relation is given by: \(\text{result} = \{w : count(w)\}\).
inputFormat
A single line of text containing a string. The string may include multiple words separated by whitespace.
outputFormat
For each unique word in the string, print a line containing the word in lowercase, a space, and its frequency. The words must be printed in lexicographical order.## sample
The cat in the hat
cat 1
hat 1
in 1
the 2
</p>