Created
September 23, 2016 13:11
-
-
Save Kishanjvaghela/cbea198a396c399893795be7f4959798 to your computer and use it in GitHub Desktop.
Problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* package codechef; // don't place package name! */ | |
import java.util.*; | |
import java.lang.*; | |
import java.io.*; | |
/* Name of the class has to be "Main" only if the class is public. */ | |
class Codechef | |
{ | |
public static void main (String[] args) throws java.lang.Exception | |
{ | |
Scanner scanner = new Scanner(System.in); | |
int size = scanner.nextInt(); | |
String input[] = new String[size]; | |
for (int i = 0; i < size; i++) { | |
input[i] = scanner.next(); | |
} | |
sortArray(input); | |
StringBuilder builder = new StringBuilder(); | |
for (int i = 0; i < size; i++) { | |
builder.append(input[i]); | |
} | |
System.out.println(builder.toString()); | |
} | |
public static void sortArray(String[] input) { | |
for (int i = 0; i < input.length; i++) { | |
for (int j = 0; j < input.length - i-1; j++) { | |
if (isLarge(input[j], input[j + 1])) { | |
String temp = input[j]; | |
input[j] = input[j + 1]; | |
input[j + 1] = temp; | |
} | |
} | |
} | |
} | |
public static boolean isLarge(String s1, String s2) { | |
return s1.compareTo(s2) < 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment