• 문제 링크
https://www.acmicpc.net/problem/14670
• 풀이 코드
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));
StringBuilder sb = new StringBuilder();
Map<Integer, Integer> map = new HashMap<>();
int n = read();
while (n-- > 0) map.put(read(), read());
int r = read();
while (r-- > 0) {
int[] arr = new int[read()];
for (int i = 0; i < arr.length; i++) arr[i] = read();
for (int i : arr) {
if (!map.containsKey(i)) {
sb.setLength(0);
sb.append("YOU DIED");
break;
} else sb.append(map.get(i)).append(' ');
}
bw.write(sb.append('\n').toString());
sb.setLength(0);
}
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' 카테고리의 다른 글
| [백준] 34692 아 마이마이 하고 싶다 - Data Structure / Java (0) | 2025.12.25 |
|---|---|
| [백준] 30949 Equal Schedules - Data Structure / Java (0) | 2025.12.24 |
| [백준] 25757 임스와 함께하는 미니게임 - Data Structure / Java (0) | 2025.12.23 |
| [백준] 14184 IOI 2017 Logo - Data Structure / Java (0) | 2025.12.22 |
| [백준] 34635 Art Installation - Greedy / Java (0) | 2025.12.21 |
댓글