## Stable Zeroing

Points: 20
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

Azuz, the scientific committee chair (has been doing nothing scientific anyway), started to learn how to code lately. He enjoyed the idea behind stable sorting and decided to make an interesting "stable zeroing" problem.

The idea behind stable zeroing is easy enough, you just need to move all the zeros to the end of the array, while leaving the non-zero elements in the same order they were before.

#### Input Specification

The first line of the array contains an integer $$1 \le n \le 10^5$$ denoting the size of the array. The second line of the input contains $$n$$ integers, the elements of the array (the elements can be very large up to $$10^{18}$$ and can be negative as well).

#### Output Specification

Output the resulting array after the transformation separated by 2 spaces.

#### Sample Input

3
1 0 2

#### Sample Output

1  2  0

#### Sample Input

5
1 0 2 0 3

#### Sample Output

1  2  3  0  0

#### Notes

The output should not have any space at the beginning or the end of the array.

• YassirSalama  commented on May 1, 2022, 11:38 a.m.

j'ai utilisé la fonction count pour compter le nombre de zéros puis je l'ai stocké dans une variable nbzero puis j'ai utilisé la fonction remove et j'ai supprimé tout les zéros du tableau puis je les ai rajoutés a la fin mais je sais pas pourquoi mon programme ne marche pas (enfin si pour le 1er et 2eme test)

• mouad_smi  commented on May 1, 2022, 10:46 p.m.

I saw your code , vector<int> v(a,a+t) , you are passing an array of long long elements to a vector of ints, it will overflow.

• AkramElOmrani  commented on July 28, 2021, 12:38 a.m. edit 2

follow up : do this is O(1) space. It doesn't make much sense here since you can just count the number of zeros but concider a function that returns the array given with the zeros in the end in O(1) space try doing this problem

• AkramElOmrani  commented on Jan. 13, 2021, 12:27 a.m.

Than why they said that the numbers of the array can be up to 10^8

• Jamesab123  commented on Aug. 30, 2020, 12:15 a.m. edit 3

Hi! If we have a number that is composed of more than one digit, should we separate these digits or not? Like 3/1 55 403, the output should be 1 55 43 0 or 1 5 5 4 3 0?

• aymanemoutei  commented on Aug. 30, 2020, 10:19 a.m.

by definition , a digit is in an integer in the range [0;9] . And you're given only digits in the input .