#C10159. Separate and Sort: Even and Odd Numbers
Separate and Sort: Even and Odd Numbers
Separate and Sort: Even and Odd Numbers
You are given a list of integers. Your task is to separate the even numbers and odd numbers, sort each group in ascending order, and then combine them together such that all even numbers come first followed by all odd numbers.
Input Format: The first line contains a single integer n which denotes the number of integers in the list. The second line contains n space-separated integers.
Output Format: Output a single line containing the sorted even numbers followed by the sorted odd numbers, each separated by a single space.
Note: If the list is empty (n = 0), output an empty line.
Example:
Input: 8
4 1 7 5 8 2 3 6
Output: 2 4 6 8 1 3 5 7
inputFormat
The input is read from standard input. The first line contains an integer n denoting the number of elements. The second line contains n space-separated integers.
outputFormat
Output the even numbers sorted in ascending order first, followed by the odd numbers sorted in ascending order. All numbers should be printed on one line and separated by spaces.
## sample8
4 1 7 5 8 2 3 6
2 4 6 8 1 3 5 7