-
Notifications
You must be signed in to change notification settings - Fork 0
/
sortofsorting.java
34 lines (33 loc) · 1.11 KB
/
sortofsorting.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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class SortOfsorting {
public static void main(String[] args) throws IOException {
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader bf = new BufferedReader(r);
PrintWriter writer = new PrintWriter(System.out);
while(true) {
int n = Integer.parseInt(bf.readLine());
if (n == 0) {
break;
} else {
String[] names = new String[n];
for (int i = 0; i < n; i++) {
names[i] = bf.readLine();
}
Arrays.sort(names, Comparator.comparing(x -> x.substring(0, 2)));
for (int i = 0; i < n; i++) {
writer.write(names[i]);
writer.println();
}
writer.println();
writer.flush();
}
}
r.close();
bf.close();
writer.close();
}
}