• 문제 링크
18294번: Biodiversity
Alicia has a huge garden which is the habitat of many animals that she really cares about. After listening to a podcast about biodiversity, she becomes very concerned about the balance between species in her garden. She wants to know if there is a species
www.acmicpc.net
• 풀이 코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.Map;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
Map<String, Integer> map = new HashMap<>();
String key, res = "";
int n = Integer.parseInt(br.readLine()), max = 0;
for (int i = 0; i < n; i++) {
map.put(key = br.readLine(), map.getOrDefault(key, 0) + 1);
if (max < map.get(key)) {
max = map.get(key);
res = key;
}
}
bw.write(max > n / 2 ? res : "NONE");
bw.flush();
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 14402 야근 - Data Structure / Java (0) | 2023.11.06 |
---|---|
[백준] 3982 Soccer Bets - Data Structure / Java (0) | 2023.11.05 |
[백준] 4881 자리수의 제곱 - Data Structure / Java (0) | 2023.11.03 |
[백준] 10105 Assigning Partners - Data Structure / Java (0) | 2023.11.02 |
[백준] 9728 Pair Sum - Data Structure / Java (0) | 2023.11.01 |
댓글