• 문제 링크
https://www.acmicpc.net/problem/5263
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.Map;
public class Main {
static Map<Integer, Integer> map = new HashMap<>();
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = read(), k = read(), i;
while (n-- > 0) map.put(i = read(), map.getOrDefault(i, 0) + 1);
bw.write(String.valueOf(find(k)));
bw.flush();
}
private static int find(int k) {
for (int key : map.keySet()) if (map.get(key) % k != 0) return key;
return 0;
}
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' 카테고리의 다른 글
[백준] 15081 Is Everybody Appy? - Data Structure / Java (0) | 2024.05.03 |
---|---|
[백준] 10689 Hamza - Data Structure / Java (0) | 2024.05.02 |
[백준] 4775 Spelling Be - Data Structure / Java (0) | 2024.04.30 |
[백준] 4649 Tanning Salon - Data Structure / Java (0) | 2024.04.29 |
[백준] 18706 Coffee - Data Structure / Java (1) | 2024.04.28 |
댓글