-
Notifications
You must be signed in to change notification settings - Fork 0
/
1302(Hashmap).java
46 lines (41 loc) · 1.26 KB
/
1302(Hashmap).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
38
39
40
41
42
43
44
45
46
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
class dic implements Comparable<String>{
String name;
public dic(String name){
this.name = name;
}
@Override
public int compareTo(String s){
return name.compareTo(s);
}
}
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
HashMap<String, Integer> hashMap = new HashMap<>();
int max = 1;
for(int i = 0; i < N; i++){
String name = br.readLine();
if(!hashMap.containsKey(name)){
hashMap.put(name, 1);
}else{
hashMap.put(name, hashMap.get(name) + 1);
if(hashMap.get(name) > max){
max = hashMap.get(name);
}
}
}
ArrayList<String>arrayList = new ArrayList<>();
for(String temp : hashMap.keySet()){
if(hashMap.get(temp) == max){
arrayList.add(temp);
}
}
Collections.sort(arrayList);
System.out.println(arrayList.get(0));
}
}