-
Notifications
You must be signed in to change notification settings - Fork 138
/
Solution.java
37 lines (29 loc) · 871 Bytes
/
Solution.java
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
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
class SortStringsComparator implements Comparator<String> {
public int compare(String x, String y) {
if (x.length() == y.length()) {
return x.compareTo(y);
}
return x.length() - y.length();
}
}
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
StringBuilder out = new StringBuilder();
int n = in.nextInt();
String[] arr = new String[n];
for(int i=0; i < n; i++){
arr[i] = in.next();
}
Arrays.sort(arr, new SortStringsComparator());
for (int i = 0; i < arr.length; i++) {
out.append(arr[i].toString() + "\n");
}
System.out.println(out.toString());
}
}