반응형
package ps.BJ.S4;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.StringTokenizer;
public class BJ_S4_11866_요세푸스문제0 {
static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
static StringBuilder output = new StringBuilder();
static StringTokenizer tokens;
static int N, K;
public static void main(String[] args) throws NumberFormatException, IOException {
tokens = new StringTokenizer(input.readLine());
N = Integer.parseInt(tokens.nextToken());
K = Integer.parseInt(tokens.nextToken());
LinkedList<Integer> LinkedList = new LinkedList<Integer>();
for (int i = 1; i <= N; i++) LinkedList.add(i);
//System.out.println(LinkedList);//입력확인
output.append("<");
while(LinkedList.size() > 1) {
for (int i = 0; i < K-1; i++) {
LinkedList.add(LinkedList.poll());
}
output.append(LinkedList.poll() + ", ");
}
output.append(LinkedList.poll() + ">");
System.out.println(output);
}
}
반응형
'코딩테스트 > 백준문제' 카테고리의 다른 글
[Java] 백준_13458_시험감독 (0) | 2021.05.19 |
---|---|
[Java] 백준_14696_딱지놀이 (0) | 2021.02.25 |
[Java] 백준_2563_색종이 (0) | 2021.02.09 |
[Java] 백준_17478_재귀함수가뭔가요 (0) | 2021.02.08 |
[Java] 백준_1244_스위치켜고끄기 (0) | 2021.02.08 |