• 문제 링크
https://www.acmicpc.net/problem/29813
• 풀이 코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
Queue<Pair> q = new ArrayDeque<>();
int n = Integer.parseInt(br.readLine());
while (n-- > 0) q.offer(new Pair(br.readLine()));
while (q.size() > 1) {
Pair p = q.poll();
while (p.i-- > 1) q.offer(q.poll());
q.poll();
}
bw.write(q.remove().s);
bw.flush();
}
private static class Pair {
String s;
int i;
Pair(String s) {
StringTokenizer st = new StringTokenizer(s);
this.s = st.nextToken();
this.i = Integer.parseInt(st.nextToken());
}
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 33241 Ducks and Sharks - Data Structure / Java (0) | 2025.02.09 |
---|---|
[백준] 11645 I’ve Been Everywhere, Man - Data Structure / Java (0) | 2025.02.08 |
[백준] 17503 맥주 축제 - Data Structure / Java (0) | 2025.02.06 |
[백준] 30614 Port Robot - Data Structure / Java (0) | 2025.02.05 |
[백준] 14455 Don't Be Last! - Data Structure / Java (0) | 2025.02.04 |
댓글