package mine.bigsorting;

import java.util.Scanner;

/*
 * Created by jsong on 01/03/2017.
 *
 * hackerrank	: https://www.hackerrank.com/jsong00505
 * github		: https://github.com/jsong00505
 * linkedin		: https://www.linkedin.com/in/junesongskorea/
 * email		: jsong00505@gmail.com
 *
 * challenge	: Week of Code 29 - Big Sorting(13.60/20)
 */
public class Solution {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		String[] unsorted = new String[n];
		for(int unsorted_i=0; unsorted_i < n; unsorted_i++){
			unsorted[unsorted_i] = in.next();
		}

		int minPos = 0;
		String temp = "";
		// your code goes here
		for(int i = 0; i < n; i++) {
			for(int j = i + 1; j < n; j++) {
				if(unsorted[i].length() > unsorted[j].length()) {
					temp = unsorted[i];
					unsorted[i] = unsorted[j];
					unsorted[j] = temp;
				} else if((unsorted[i].length() == unsorted[j].length()) && (unsorted[i].compareTo(unsorted[j]) > 0)) {
					temp = unsorted[i];
					unsorted[i] = unsorted[j];
					unsorted[j] = temp;
				}
			}
		}

		for(int i = 0; i < n; i++) {
			System.out.println(unsorted[i]);
		}

	}
}

@@ -19,16 +19,70 @@
 rting;%0A%0A
+import java.util.Arrays;%0Aimport java.util.Comparator;%0A
 import j
@@ -659,46 +659,8 @@
 %09%7D%0A%0A
-%09%09int minPos = 0;%0A%09%09String temp = %22%22;%0A
 %09%09//
@@ -684,489 +684,468 @@
 ere%0A
+%0A
 %09%09
-for(int i = 0; i %3C n; i++) %7B%0A%09%09%09for(int j = i + 1; j %3C n; j++) %7B%0A%09%09%09%09if(unsorted%5Bi%5D.length() %3E unsorted%5Bj%5D.length()) %7B%0A%09%09%09%09%09temp = unsorted%5Bi%5D;%0A%09%09%09%09%09unsorted%5Bi%5D = unsorted%5Bj%5D;%0A%09%09%09%09%09unsorted%5Bj%5D = temp;%0A%09%09%09%09%7D else if((unsorted%5Bi%5D.length() == unsorted%5Bj%5D.length()) && (unsorted%5Bi%5D.compareTo(unsorted%5Bj%5D) %3E 0)) %7B%0A%09%09%09%09%09temp = unsorted%5Bi%5D;%0A%09%09%09%09%09unsorted%5Bi%5D = unsorted%5Bj%5D;%0A%09%09%09%09%09unsorted%5Bj%5D = temp
+// sorting by using Array class%0A%09%09Arrays.sort(unsorted, new BigSortingComparator());%0A%0A%0A%09%09// print sorted array%0A%09%09for(String s: unsorted) %7B%0A%09%09%09System.out.println(s);%0A%09%09%7D%0A%0A%09%09// close%0A%09%09in.close();%0A%0A%09%7D%0A%0A%09static class BigSortingComparator implements Comparator%3CString%3E %7B%0A%09%09public int compare(String left, String right) %7B%0A%09%09%09if(left.length() != right.length()) %7B%0A%09%09%09%09return left.length() - right.length()
 ;%0A
-%09
 %09%09%09%7D
-%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09for(int i = 0; i %3C n; i++) %7B%0A%09%09%09System.out.println(unsorted%5Bi%5D
+ else %7B%0A%09%09%09%09return left.compareTo(right
 );%0A
+%09
 %09%09%7D%0A%0A
+%09%09%7D%0A
 %09%7D%0A%7D

solve the problem by using sort method in Array class