• 문제 링크
25631번: 마트료시카 합치기
마트료시카는 속이 비어있는 인형이다. 성빈이는 $N$개의 마트료시카를 가지고 있다. $i$번째 마트료시카의 크기는 $a_i$이고, 마트료시카 속은 모두 비어있다. 성빈이는 남아 있는 마트료시카 중
www.acmicpc.net
• 풀이 코드
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 n = read(), a;
while (n-- > 0) map.put(a = read(), map.getOrDefault(a, 0) + 1);
int max = 0;
for (int i : map.values()) max = Math.max(max, i);
bw.write(String.valueOf(max));
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' 카테고리의 다른 글
[백준] 31562 전주 듣고 노래 맞히기 - Data Structure / Java (0) | 2024.04.03 |
---|---|
[백준] 31718 Double Up - Data Structure / Java (0) | 2024.04.02 |
[백준] 2776 암기왕 - Data Structure / Java (0) | 2024.03.31 |
[백준] 10815 숫자 카드 - Data Structure / Java (0) | 2024.03.30 |
[백준] 17599 Bags - Data Structure / Java (0) | 2024.03.29 |
댓글