
https://www.acmicpc.net/problem/1158
k-1명의 사람들은 큐의 뒤로 보내고, k번째 사람은 제거한다. from collections import deque
n, k = map(int, input().split())
q = deque()
ans = []
for i in range(n):
q.append(i+1)
while q:
for i in range(k-1):
a = q.popleft()
q.append(a)
ans.append(q.popleft())
print("<" + ', '.join(map(str, ans)) + ">")
큐(deque)를 떠올리고, 사용할수 있으면 되는 문제였다.
파이썬에서 리스트를 쉼표로 구분해서 출력하고 싶을 때는
👉 ', '.join(map(str, 리스트)) 를 사용하면 된다.
ans = [3, 6, 2, 7, 5, 1, 4]
print(', '.join(map(str, ans)))
# 출력: 3, 6, 2, 7, 5, 1, 4
join()은 문자열 리스트에만 사용할 수 있기 때문에,
숫자 리스트일 경우 map(str, 리스트)로 문자열로 먼저 변환해줘야 해요.