#C14042. Move Zeros
Move Zeros
Move Zeros
Given a list of integers \( [a_1, a_2, \ldots, a_n] \), rearrange the list so that all non-zero elements maintain their original order and all zeros are moved to the end of the list.
For example, if the input is [0, 1, 0, 3, 12]
, then the output should be [1, 3, 12, 0, 0]
.
inputFormat
The input is read from stdin and consists of two lines:
- The first line contains an integer \(n\), denoting the number of elements in the list.
- The second line contains \(n\) space-separated integers.
If \(n = 0\), the second line will be empty.
outputFormat
Output the rearranged list to stdout in one line. The elements should be space-separated. If the list is empty, output an empty line.
## sample5
0 1 0 3 12
1 3 12 0 0
</p>