• 문제 링크
https://www.acmicpc.net/problem/2592
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.Map;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
Map<Integer, Integer> map = new HashMap<>();
int sum = 0, max = 0, mode = 0;
for (int i = 0; i < 10; i++) {
int n = read(), m = map.getOrDefault(n, 0) + 1;
sum += n;
map.put(n, m);
if (max < m) {
max = m;
mode = n;
}
}
bw.write(sum / 10 + "\n" + mode);
bw.flush();
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 1225 이상한 곱셈 - Implementation / Java (0) | 2024.11.04 |
---|---|
[백준] 1919 애너그램 만들기 - Implementation / Java (0) | 2024.11.03 |
[백준] 2476 주사위 게임 - Implementation / Java (0) | 2024.11.01 |
[백준] 11328 Strfry - Implementation / Java (0) | 2024.10.31 |
[백준] 6779 Who Has Seen The Wind - Brute Force / Java (0) | 2024.10.30 |
댓글