#C12474. Sort Dictionary Keys by Values in Descending Order
Sort Dictionary Keys by Values in Descending Order
Sort Dictionary Keys by Values in Descending Order
You are given a dictionary with string keys and integer values. Your task is to sort the keys in descending order according to their associated integer values. In the event that two keys have the same value, maintain the order in which they appear in the input.
The program must accept input from stdin and produce its output to stdout. The output should consist of the sorted keys in a single line, separated by a single space.
Note: If the dictionary is empty, output nothing.
inputFormat
The first line of input contains an integer N, representing the number of key-value pairs. Each of the following N lines contains a key (a string without spaces) and an integer value separated by a space. If N is 0, no further input follows.
outputFormat
Output a single line containing the keys of the dictionary, sorted in descending order based on their values. The keys should be separated by a single space. For an empty dictionary, output nothing.## sample
3
a 3
b 1
c 2
a c b