#C12324. Word Length and Dictionary Sorting
Word Length and Dictionary Sorting
Word Length and Dictionary Sorting
Given a list of words, your task is to create a dictionary (or map) that maps each word to its length, and then output the dictionary sorted in descending order based on word lengths. In the event that two words have the same length, their original order of appearance should be maintained.
Input Format: The first line contains an integer \( n \) representing the number of words. The second line contains \( n \) space-separated words.
Output Format: For each word in the sorted order, output a line containing the word followed by its length, separated by a space.
Note: If \( n = 0 \), no output should be produced.
inputFormat
The first line contains an integer ( n ) (( n \ge 0 )). The second line contains ( n ) space-separated words.
outputFormat
Print each word along with its length on a separate line, sorted by length in descending order. Each line should be in the format: word length
.## sample
4
apple banana cherry date
banana 6
cherry 6
apple 5
date 4
</p>