-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBJAlgo_1302.java
More file actions
35 lines (28 loc) · 1.1 KB
/
Copy pathBJAlgo_1302.java
File metadata and controls
35 lines (28 loc) · 1.1 KB
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
import jdk.dynalink.linker.ConversionComparator;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class BJAlgo_1302 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
Map<String, Integer> books = new HashMap<>();
for (int i = 0; i < n; i++) {
String book = br.readLine();
if (books.containsKey(book)) {
books.put(book, books.get(book) + 1);
} else {
books.put(book, 1);
}
}
List<Map.Entry<String, Integer>> entryList = new ArrayList<>(books.entrySet());
Collections.sort(entryList, (o1, o2) -> {
if (o1.getValue().compareTo(o2.getValue()) == 0) {
return o2.getKey().compareTo(o1.getKey());
} else {
return o1.getValue().compareTo(o2.getValue());
}
});
System.out.println(entryList.get(entryList.size() - 1).getKey());
}
}