We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7bdf288 commit c7cb402Copy full SHA for c7cb402
Hongjoo/백준/요세푸스문제.py
@@ -0,0 +1,25 @@
1
+"""
2
+[BOJ]#1158. 요세푸스문제: 실버 4
3
+https://www.acmicpc.net/problem/1158
4
+
5
+-1 ~ n 번쨰 사람 중 순서대로 k 번째 사람 제거
6
+- 출력 : 제거되는 순서대로 출력
7
8
+#FL0W
9
+유형 : 구현, 큐
10
+원형 큐 배치하기
11
+ 7,3 : 0~ 6
12
+ <3, 6, 2, 7, 5, 1, 4>
13
14
+import sys
15
+N , K = map(int , sys.stdin.readline().split())
16
17
+#1. 원형 큐 만들기
18
+elements = [i for i in range(1,N+1)]
19
+answer = []
20
+p = 0
21
+while elements :
22
+ p = (p + K-1) % len(elements)
23
+ answer.append(elements.pop(p))
24
+#2.출력
25
+print("<"+", ".join(list(map(str, answer))) + ">")
0 commit comments