#C13151. Separate Even and Odd Numbers
Separate Even and Odd Numbers
Separate Even and Odd Numbers
You are given a list of integers. Your task is to separate the even and odd numbers from the list while preserving their original order.
Specifically, the input will be provided via standard input. The first line contains an integer n denoting the number of integers. The second line contains n space-separated integers.
Your output should consist of two lines: the first line displays all even numbers (separated by a single space) and the second line displays all odd numbers (separated by a single space). If there are no numbers of a particular type, output an empty line for that category.
For example, given the input:
6 10 21 32 43 54 65
The output should be:
10 32 54 21 43 65
Mathematically, if the list is \(A = [a_1, a_2, \dots, a_n]\), then define the even numbers as \(E = [a_i \in A \mid a_i \equiv 0 \pmod{2}]\) and the odd numbers as \(O = [a_i \in A \mid a_i \equiv 1 \pmod{2}]\). Your program should compute and print \(E\) followed by \(O\).
inputFormat
Input Format:
- The first line contains an integer \(n\), the number of elements in the list.
- The second line contains \(n\) space-separated integers.
Input is given via stdin
.
outputFormat
Output Format:
- Print two lines.
- The first line should contain all even numbers separated by a single space.
- The second line should contain all odd numbers separated by a single space.
Output should be sent to stdout
. If no even (or odd) numbers exist, print a blank line for that category.
6
10 21 32 43 54 65
10 32 54
21 43 65
</p>