import java.util.*;
public class Splitting
{
public static void main(String[] args)
{
int n,j=0,i;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int a[] = new int[n];
for (i = 0; i < n; i++)
{
a[i] = sc.nextInt();
}
for (i=0;i<n;i++)
{
if(a[i]==0)
{
a[j]=a[i];
j++;
}
}
while(j<n)
{
a[j]=1;
j++;
}
for(i=0;i<a.length;i++)
{
System.out.print(a[i]+" ");
}
}
}
i/p: 10
0 1 1 0 1 0 1 0 1 0
o/p:
0 0 0 0 0 1 1 1 1 1
public class Splitting
{
public static void main(String[] args)
{
int n,j=0,i;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int a[] = new int[n];
for (i = 0; i < n; i++)
{
a[i] = sc.nextInt();
}
for (i=0;i<n;i++)
{
if(a[i]==0)
{
a[j]=a[i];
j++;
}
}
while(j<n)
{
a[j]=1;
j++;
}
for(i=0;i<a.length;i++)
{
System.out.print(a[i]+" ");
}
}
}
i/p: 10
0 1 1 0 1 0 1 0 1 0
o/p:
0 0 0 0 0 1 1 1 1 1
No comments:
Post a Comment