반응형
문제
https://www.acmicpc.net/problem/2161
해설
큐의 구조를 활용하면 된다.
def solution(cards):
answer = []
while len(cards)-1:
answer.append(cards.pop(0))
cards.insert(len(cards)-1, cards.pop(0))
answer.append(cards.pop(0))
return " ".join(answer)
num = int(input())
print(solution([str(i+1) for i in range(num)]))
반응형