#K61987. Group Even and Odd Numbers
Group Even and Odd Numbers
Group Even and Odd Numbers
You are given a list of integers. Your task is to separate the list into two groups: odd numbers and even numbers. Then, sort each group in ascending order and output them as comma-separated values on two separate lines. The first line should contain the sorted odd numbers and the second line should contain the sorted even numbers. If a group is empty, output an empty line for that group.
Note: The input will be provided via STDIN, and the output must be printed to STDOUT. Ensure that the output consists of exactly two lines.
Examples:
Input: 8 4 1 3 2 7 6 8 9</p>Output: 1,3,7,9 2,4,6,8
Input: 4 11 13 15 17
Output: 11,13,15,17
Input: 4 2 4 6 8
Output:
2,4,6,8
inputFormat
The first line of input contains an integer n (n ≥ 0) representing the number of elements in the list. The second line (if n > 0) contains n space-separated integers.
For example:
8 4 1 3 2 7 6 8 9
outputFormat
Print exactly two lines as follows:
- The first line contains the odd numbers from the list in ascending order, joined by commas. If there are no odd numbers, print an empty line.
- The second line contains the even numbers from the list in ascending order, joined by commas. If there are no even numbers, print an empty line.
8
4 1 3 2 7 6 8 9
1,3,7,9
2,4,6,8
</p>