#C11588. Word Occurrence Counter
Word Occurrence Counter
Word Occurrence Counter
In this problem, you are given a text consisting of multiple lines. Your task is to count the occurrences of each unique word in the text. Words are compared in a case‐insensitive manner, but the output must preserve the original casing of the first occurrence of each word. Formally, if a word appears multiple times, let the first occurrence (in its original case) be the representative, and count all occurrences regardless of case. For example, if the input is:
3 Hello world hello Python Python world of code
then the correct output is:
Hello 2 world 2 Python 2 of 1 code 1
Note: In mathematical terms, if we denote the number of lines by , then the text is a sequence of strings. The solution should output each word in the order of its first appearance along with its frequency.
Good luck and happy coding!
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer (), which represents the number of lines of text.
- Each of the following lines contains a string that may include spaces.
Words in a line are separated by whitespace.
outputFormat
Print the unique words along with their counts, one pair per line. Each line should contain the word (using the original casing from its first occurrence) followed by a space and its count. The output order must follow the order of the words' first appearance in the text.## sample
1
hello world
hello 1
world 1
</p>