Skip to content

Commit 6d349e7

Browse files
committed
[BOJ] #1158. 요세푸스 문제 / 실버4 / 10분 / 성공
1 parent 8dbef07 commit 6d349e7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import sys
2+
from collections import deque
3+
input = sys.stdin.readline
4+
5+
N, K = map(int, input().split())
6+
# 1번부터 N번까지 사람을 큐에 넣기
7+
people = deque([i+1 for i in range(N)])
8+
answer = [] # 제거된 순서를 저장할 리스트
9+
10+
while people:
11+
# K-1번 앞의 원소를 빼서 뒤로 보냄 (원형 이동)
12+
for _ in range(K-1):
13+
cur = people.popleft()
14+
people.append(cur)
15+
# K번째에서 제거
16+
answer.append(people.popleft())
17+
18+
# 정답 출력
19+
print("<" + ", ".join(map(str, answer)) + ">")

0 commit comments

Comments
 (0)