-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBigSorting.java
More file actions
39 lines (30 loc) · 831 Bytes
/
BigSorting.java
File metadata and controls
39 lines (30 loc) · 831 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
37
38
39
package sorting;
import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;
public class BigSorting {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
TreeSet<String> ts= new TreeSet<>(new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
if(o1.length()>o2.length()){
return 1;
}
else if(o1.length()<o2.length()){
return -1;
}
else{
return o1.compareTo(o2)!=0?o1.compareTo(o2):1;
}
}
});
for(int unsorted_i=0; unsorted_i < n; unsorted_i++){
ts.add(in.next());
}
Object[] op= ts.toArray();
for(int i=0;i<op.length;i++)
System.out.println(op[i]);
}
}