• 문제 링크
https://www.acmicpc.net/problem/9863
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayDeque;
import java.util.Queue;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder();
Queue<Integer> q = new ArrayDeque<>();
int n;
while ((n = read()) != 0) {
for (int i = 1; i <= n; i++) q.offer(i);
int m = read(), k = read();
while (k-- > 0) {
for (int i = 1; i < m; i++) q.offer(q.poll());
if (k > 0) q.poll();
}
sb.append(q.poll()).append("\n");
q.clear();
}
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' 카테고리의 다른 글
[백준] 24776 Recount - Data Structure / Java (0) | 2024.05.30 |
---|---|
[백준] 7800 The Chosen Sub Matrix - Data Structure / Java (0) | 2024.05.29 |
[백준] 25643 문자열 탑 쌓기 - Brute Force / Java (0) | 2024.05.27 |
[백준] 18141 Are They All Integers? - Brute Force / Java (0) | 2024.05.26 |
[백준] 5947 Book Club - Brute Force / Java (0) | 2024.05.25 |
댓글