SMALL
문제

코드
from collections import deque
import sys
input = sys.stdin.readline
if __name__ == "__main__":
n, k = map(int, input().split())
table = deque(range(1, n+1))
result = []
while table:
for _ in range(k-1):
table.append(table.popleft())
result.append(table.popleft())
print("<" + ", ".join(map(str, result)) + ">")
큐를 연습할 수 있는 대표 문제이다.
원 순열로 돌아가면서 k번째 사람을 result라는 새 리스트에 담아준다.
popleft() 대신에 rotate(-(k-1))도 가능하다.
table.rotate(-(k-1))
result.append(table.popleft())
LIST
'CODE' 카테고리의 다른 글
| 백준 BOJ 2075 N번째 큰 수 (0) | 2026.04.29 |
|---|---|
| 백준 BOJ 1202 보석 도둑 (0) | 2026.04.29 |
| 백준 BOJ 2164 카드2 (0) | 2026.04.28 |
| n진수 만들기 (0) | 2026.04.24 |
| LEETCODE 풀 문제 모음 (0) | 2026.04.23 |