728x90
1. 문제
2. 풀이
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 BOJ_11866_요세푸스문제0 {
public static void main(String[] args) throws IOException {
StringTokenizer st = new StringTokenizer(new BufferedReader(new InputStreamReader(System.in)).readLine());
int N = Integer.parseInt(st.nextToken());
int K = Integer.parseInt(st.nextToken());
StringBuilder sb = new StringBuilder();
sb.append("<");
Queue<Integer> queue = new LinkedList<>();
for(int i=1;i<=N;i++){
queue.offer(i);
}
while(queue.size()>1){
for(int i=1;i<K;i++){
queue.offer(queue.poll());
}
sb.append(queue.poll()).append(", ");
}
sb.append(queue.poll()).append(">");
System.out.println(sb);
}
}
3. 결과
'코딩테스트 > BOJ' 카테고리의 다른 글
[BOJ] 10866 덱 - JAVA (0) | 2022.02.07 |
---|---|
[BOJ] 1966 프린터큐 - JAVA (0) | 2022.02.07 |
[BOJ] 2164 카드2 - JAVA (0) | 2022.02.06 |
[BOJ] 18258 큐2 - JAVA (0) | 2022.02.06 |
[BOJ] 17298 오큰수 - JAVA (0) | 2022.02.05 |
댓글