-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSortOfSorting.java
More file actions
39 lines (32 loc) · 839 Bytes
/
SortOfSorting.java
File metadata and controls
39 lines (32 loc) · 839 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
//Name: Nguyen Minh Hieu
//https://open.kattis.com/problems/sortofsorting
import java.util.*;
public class SortOfSorting {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num_case = 1;
while (num_case != 0) {
num_case = sc.nextInt();
sc.nextLine();
if (num_case == 0) break;
String[] list = new String[num_case];
for (int i = 0; i < num_case; i++) {
list[i] = sc.nextLine();
}
Comparator<String> c = new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
if (s1.charAt(0) != s2.charAt(0)) {
return s1.charAt(0) - s2.charAt(0);
} else {
return s1.charAt(1) - s2.charAt(1);
}
}
};
Arrays.sort(list,c);
for (String result: list)
System.out.println(result);
System.out.println("");
}
}
}