-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhackerRankBigSorting.java
More file actions
36 lines (30 loc) · 903 Bytes
/
hackerRankBigSorting.java
File metadata and controls
36 lines (30 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package javaBackjoon;
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class hackerRankBigSorting {
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();
}
// your code goes here
Arrays.sort(unsorted, new Comparator<String> () {
@Override
public int compare(String a, String b) {
if(a.length() != b.length()) {
return a.length() - b.length();
}
else
return a.compareTo(b);
}
});
for(int i = 0; i < n; i++) {
System.out.println(unsorted[i]);
}
}
}