// 최애의 팀원
package Silver_III_3;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
public class Ex29813 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
Queue<String> queue = new LinkedList<>();
Queue<Integer> num = new LinkedList<>();
for (int i = 0; i < n; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
String initial = st.nextToken();
int x = Integer.parseInt(st.nextToken());
queue.add(initial);
num.add(x);
}
while (queue.size() > 1) {
queue.poll();
int numberOfPass = (num.poll()-1) % queue.size();
while (numberOfPass != 0) {
queue.add(queue.poll());
num.add(num.poll());
numberOfPass--;
}
queue.poll();
num.poll();
}
System.out.println(queue.poll());
num.poll();
}
}
내용 이해가 잘 되지 않아서 곤란했던 문제다. 배열을 이용하면 더 나은 코드가 될 것 같지만, 빠르고 편하게 큐를 사용했다.
'백준 풀이 > 자바(Java)' 카테고리의 다른 글
백준 1259 자바 - 팰린드롬수 (0) | 2024.07.08 |
---|---|
백준 5585 자바 - 거스름돈 (0) | 2024.07.08 |
백준 26561 자바 - Population (0) | 2024.07.08 |
백준 9295 자바 - 주사위 (0) | 2024.07.06 |
백준 24365 자바 - ПЧЕЛИЧКАТА МАЯ (0) | 2024.07.04 |