• 문제 링크
https://www.acmicpc.net/problem/30068
• 풀이 코드
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) {
int t = read(), i = read();
if (map.containsKey(i)) sb.append(i).append(" ").append(t - map.get(i)).append("\n");
else map.put(i, t);
}
bw.write(sb.toString());
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' 카테고리의 다른 글
[백준] 1159 농구 경기 - Implementation / Java (0) | 2024.08.27 |
---|---|
[백준] 1100 하얀 칸 - Implementation / Java (0) | 2024.08.26 |
[백준] 29934 Important Messages - Data Structure / Java (0) | 2024.08.24 |
[백준] 10489 Even Up Solitaire - Data Structure / Java (0) | 2024.08.23 |
[백준] 8538 Bałagan i Stonki - Data Structure / Java (0) | 2024.08.22 |
댓글