All problems

Move Zeroes to End

mediumPythonArrays

Riverbend Hardware counts stock by walking one aisle end to end and writing down the units held at each position in the order they are passed. A zero means that position is empty. The reorder sheet then has to list every position that still holds stock, in the order the counter walked them, with the empty positions collected together at the end. The walking order is the whole point: the stock hand works down the aisle from the sheet.

Task: Print the counts with every zero moved to the end.

Input

A single line holding between 1 and 1000 integers separated by single spaces. Zeroes may sit anywhere, including at the front, and every value may be zero.

Output

One line holding the same numbers separated by single spaces: first every non-zero count in the order it appeared, then one zero for each zero that was in the input.

Example:

Input:
0 1 0 3 12

Output:
1 3 12 0 0

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…