#C7998. Sort Dictionary Values
Sort Dictionary Values
Sort Dictionary Values
In this problem, you are given a dictionary-like input where each entry contains a key (string) and a list of integers. Your task is to sort the list of integers for each key in ascending order and output the result.
Problem Details:
You will be provided with an integer N on the first line representing the number of key-value pairs. The following N lines each contain a key and its associated list of integers. Each line has the following format:
key m a1 a2 ... am
where key
is a string, m
is the number of integers in the list (which could be 0), and a1, a2, ..., am
are the integers.
You need to sort each list in ascending order and then output each pair in the format:
key: sorted_numbers
If the list is empty, simply output the key followed by a colon.
The solution should read from standard input (stdin) and output to standard output (stdout).
inputFormat
The first line contains an integer N, the number of key-value pairs. Each of the next N lines contains a key (string) followed by an integer m and then m integers separated by spaces. For example:
3
a 3 3 1 2
b 2 5 4
c 4 8 7 6 9
outputFormat
Output should contain N lines. For each input line, print the key followed by a colon and the sorted list of integers (in ascending order) separated by spaces. If the list is empty, just print the key and a colon. For the sample input above, the output would be:
a: 1 2 3
b: 4 5
c: 6 7 8 9## sample
3
a 3 3 1 2
b 2 5 4
c 4 8 7 6 9
a: 1 2 3
b: 4 5
c: 6 7 8 9
</p>