Canna

Tuesday, 25 September 2018

Turbo Sort

  • Problem Description

    Given the list of numbers, you are to sort them in non decreasing order.
    Input

    t ? the number of numbers in list, then t lines follow [t <= 10^6]. 
    Each line contains one integer: N [0 <= N <= 10^6]
    Output

    Output given numbers in non decreasing order.
  • Test Case 1

    Input (stdin)
    6 
    
    5 4 3 2 1 1
    
    
    Expected Output
    1
    
    1
    
    2
    
    3
    
    4
    
    5
  • Test Case 2

    Input (stdin)
    5
    
    5 3 6 7 1
    
    
    Expected Output
    1
    
    3
    
    5
    
    6
    
    7
  • Program
  • #include<stdio.h>
     
    int main()
    {
            int i,num,arr[1000001]={0},n;
            scanf("%d",&num);
            for(i=0;i<num;i++)
            {
                   scanf("%d",&n);
                   arr[n]++;
            }
            for(i=0;i<1000001;i++)
                   if(arr[i])
                           while(arr[i]--)
                                   printf("%d\n",i);
            return 0;
    }

No comments:

Post a Comment

Note: only a member of this blog may post a comment.