문제링크
https://www.acmicpc.net/problem/1302
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
public class Main_1302 {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
HashMap<String,Integer> map = new HashMap<String,Integer>();
for(int i=0;i<N;i++) {
String str = br.readLine();
if(map.containsKey(str))
map.put(str, map.get(str)+1);
else
map.put(str, 1);
}
int max = 0;
String str = "";
for(String key: map.keySet()) {
if(max<map.get(key)) {
max = map.get(key);
str = key;
}
else if(max == map.get(key)) {
if(key.compareTo(str)<0) {
str = key;
}
}
}
System.out.println(str);
}
}
'알고리즘 > 백준' 카테고리의 다른 글
[JAVA]백준_10819_차이를 최대로 (0) | 2021.02.07 |
---|---|
[JAVA]백준_2309_일곱난쟁이 (0) | 2021.02.07 |
[JAVA]백준_10974_모든 순열 (0) | 2021.02.07 |
[JAVA]백준_5597_과제 안 내신 분..? (0) | 2021.02.07 |
[JAVA]백준_2167_별찍기 -6 (0) | 2021.02.07 |