Skip to content

Commit 5487444

Browse files
authored
[백준 1158] 요세푸스 문제 - 자료구조
1 parent 9e8a8e9 commit 5487444

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
7,3 <- input
3+
7 -> 전체 인원수
4+
3 -> 제거 순번
5+
6+
큐로 뺐다가 넣으면 될듯
7+
*/
8+
9+
// 22:13
10+
11+
import java.io.*;
12+
import java.util.*;
13+
14+
public class Boj1158{
15+
16+
public static void main(String...args) throws Exception{
17+
var br = new BufferedReader(new InputStreamReader(System.in));
18+
var sb = new StringBuilder();
19+
20+
var queue = new LinkedList<Integer>();
21+
var inputs= br.readLine().split(" ");
22+
23+
var count = Integer.parseInt(inputs[0]); // 전체 인원수
24+
var orderOfRemoval = Integer.parseInt(inputs[1]);// 제거 순번
25+
26+
// 초기화
27+
for(int i = 1; i <= count; i++){
28+
queue.add(i);
29+
}
30+
31+
int repeatCount = 1;
32+
while(queue.size() > 0){
33+
var element = queue.poll();
34+
35+
if(repeatCount++ == orderOfRemoval){
36+
sb.append(element);
37+
if(queue.size() != 0){
38+
sb.append(", ");
39+
}
40+
41+
repeatCount= 1;
42+
continue;
43+
}
44+
45+
queue.add(element);
46+
}
47+
48+
System.out.println(String.format("<%s>", sb) );
49+
}
50+
}

0 commit comments

Comments
 (0)