Posts

Search

P 303 - A Sorted Team

The number of applicants have now increased and the coach is now tired of trying to eliminate the shorter players. Instead, he just wants everyone to come and stand in ascending order of their heights, following the same routine he tried to use above.

Formally, use the selection sort technique to sort the array of player heights.

INPUT

The first line of input is n (1≤n≤100), the number of applicants for the basketball team The second line of input is the heights of the n players (positive numbers) each separated by a space.

OUTPUT

Print the heights of the players in a line after the sorting routine.

Sample Input 0

8
3 4 5 2 4 10 18 1

Sample Output 0

1 2 3 4 4 5 10 18 

Solution :

import java.io.*;
import java.util.*;

public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc=new Scanner(System.in);
        int a= sc.nextInt();
        int ar[] = new int[a];
        for(int i=0;i<a;i++)
            ar[i]=sc.nextInt();
        Arrays.sort(ar);
        for(int i=0;i<a;i++)
            System.out.print(ar[i]+" ");
        
    }
}