#K91137. Sort Even and Odd Numbers
Sort Even and Odd Numbers
Sort Even and Odd Numbers
You are given a list of \( n \) integers \( a_1, a_2, \ldots, a_n \). Your task is to separate them into two groups:
- Even numbers: All numbers \( a_i \) such that \( a_i \mod 2 = 0 \). These should be sorted in ascending order.
- Odd numbers: All numbers \( a_i \) such that \( a_i \mod 2 \neq 0 \). These should be sorted in descending order.
For example, if the input list is 2 3 5 8 1 4
, then the even numbers are \( [2, 4, 8] \) and the odd numbers are \( [5, 3, 1] \). The output should contain two lines: the first line for evens and the second line for odds. If one of the groups is empty, output an empty line for that group.
inputFormat
The input is given via standard input (stdin). The first line contains a single integer \( n \) representing the number of integers. The second line contains \( n \) space-separated integers.
outputFormat
Output two lines to standard output (stdout):
- The first line should contain the even numbers sorted in ascending order, separated by a single space. If there are no even numbers, print an empty line.
- The second line should contain the odd numbers sorted in descending order, separated by a single space. If there are no odd numbers, print an empty line.
6
2 3 5 8 1 4
2 4 8
5 3 1
</p>