알고리즘 문제/알고리즘 문제풀이

백준 11866 요세푸스 문제 0

태윤2 2020. 10. 25. 20:16

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from collections import deque
 
n, k = map(int, input().split())
 
queue = deque()
li = []
for i in range(n):
    queue.append(i + 1)
print('<',end='')
while len(queue) > 0:
    for i in range(k - 1):
        queue.append(queue.popleft())
    if len(queue) == 1:
        print(queue.popleft(),end='')
        break
    print(queue.popleft(),end=', ')
 
print(','.join(li),end='>')
cs