#K71922. Arrange Friends by Birth Month
Arrange Friends by Birth Month
Arrange Friends by Birth Month
You are given an integer n representing the number of friends. Then, following are 2n integers where each pair consists of the birth month (an integer from 1 to 12) and a unique identification number of a friend. Your task is to group the friends by their birth month. For each month, list the friends' identification numbers in descending order (i.e. from highest to lowest). Then, output the 12 groups corresponding to months 1 through 12. If no friend was born in a given month, output an empty line for that month.
Note: The input is read from standard input (stdin
) and output is printed to standard output (stdout
).
inputFormat
The first line contains a non-negative integer n representing the number of friends. The second line contains 2n space-separated integers. Each pair of integers represent the birth month and the identification number of a friend, respectively.
For example, if n = 5, the next line may contain: 3 101 5 102 3 103 1 104 2 105
.
outputFormat
The output should contain exactly 12 lines. The i-th line (1-indexed) corresponds to month i:
- If there are friends born in that month, output their identification numbers sorted in descending order separated by a single space.
- If there is no friend for that month, output an empty line.
5
3 101 5 102 3 103 1 104 2 105
104
105
103 101
102
</p>