Problem 25

19 comments on “Problem 25”


  • samba

    import java.util.Scanner;
    class zerolast
    {
    public static void main(String[] args)
    {
    int a[]={1, 6, 7, 4, 0, 3, 0, 2, 7, 0, 6, 0, 9};
    int n=a.length;
    for(int i=0;i<n;i++)
    {
    if(a[i]==0)
    {
    for(int j=i;j<n-2;j++)
    {
    a[j]=a[j+1];
    }
    a[n-1]=0;
    }

    }
    for(int i=0;i<a.length;i++)
    System.out.println(a[i]);
    }
    }


  • Pranjal

    arr=[1, 2, 0, 0, 0, 3, 6]
    def zeros(arr):
    count=0
    for i in range(len(arr)):
    if arr[i]==0:
    count+=1
    i=0
    j=len(arr)-1
    while i<len(arr)-count:
    if arr[i]==0:
    if arr[j]==0:
    j-=1
    else:
    arr[j],arr[i]=arr[i],arr[j]
    i+=1
    j-=1
    else:
    i+=1
    return arr
    zeros(arr)


  • Kritika

    l1=[1,3,6,0,3,54,76,0,3,5,0]

    l2=[]

    for i in l1:
    if i == 0:
    l2.append(i)
    l1.remove(i)

    for item in l2:
    l1.append(item)

    print(l1)


  • shushank

    #Python
    l=list(map(int,input().split(” “)))
    c=0
    l1=[]
    for i in range(len(l)):
    if l[i]==0:
    c+=1
    else:
    l1.append(l[i])
    for i in range(c):
    l1.append(0)
    print(*l1)


  • amit

    int main()
    {
    int arr[20];
    int arr2[20];
    int bound,k=0;
    scanf(“%d”,&bound);
    for(int i=0;i<bound;i++)
    scanf("%d",&arr[i]);
    for(int j=0;j<bound;j++){
    if(arr[j]!=0){
    printf("%d",arr[j]);
    k++;
    }
    }
    for(int i=0;i<bound-k;i++)
    printf("%d",0);
    }