#C13828. Case-Insensitive Word Count with Reverse Alphabetical Order
Case-Insensitive Word Count with Reverse Alphabetical Order
Case-Insensitive Word Count with Reverse Alphabetical Order
You are given a list of words. Your task is to count the number of occurrences of each word with the following conditions:
- Counting is case-insensitive. For example, "Apple" and "apple" should be considered the same word.
- The output should list each unique word along with its frequency.
- The results must be sorted by the word in reverse alphabetical order (i.e. words that would appear later in the alphabet come first).
Note: All input is provided through stdin
and results should be printed to stdout
.
For example, if the input list is:
6 apple banana apple Apple banana cherry
Then, after converting words to lowercase and counting occurrences, the result should be:
cherry 1 banana 2 apple 3
Your solution should handle cases with an empty list, a single word, multiple words with varying cases, and larger inputs.
inputFormat
The first line of input contains an integer n (0 ≤ n ≤ 105
), indicating the number of words. Each of the following n lines contains a single word consisting of letters.
outputFormat
For each unique word in the input, print a line containing the word and its count, separated by a space, in reverse alphabetical order.
If there are no words (i.e. when n=0), do not print anything.
## sample6
apple
banana
apple
Apple
banana
cherry
cherry 1
banana 2
apple 3
</p>