🧩PS/🥉Easy
[JAVA] 백준 11866번 - 요세푸스 문제 0
Cocoon_
2021. 12. 13. 05:56
반응형
📖 문제
📋 코드
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int K = sc.nextInt();
Queue<Integer> q = new LinkedList<>();
for (int i = 1; i <= N; i++) {
q.offer(i);
}
int cnt = 0;
String ans = "<";
while (!q.isEmpty()) {
cnt++;
if(cnt == K) {
ans += q.poll()+", ";
cnt = 0;
}else {
q.offer(q.poll());
}
}
ans = ans.substring(0,ans.length()-2);
ans += ">";
System.out.println(ans);
}
}
👨🏻💻 결과
🔗 링크
https://www.acmicpc.net/problem/11866
11866번: 요세푸스 문제 0
첫째 줄에 N과 K가 빈 칸을 사이에 두고 순서대로 주어진다. (1 ≤ K ≤ N ≤ 1,000)
www.acmicpc.net
반응형