[SWEA] 1225 [S/W 문제해결 기본] 7일차 - 암호생성기

[SWEA] 1225 [S/W 문제해결 기본] 7일차 - 암호생성기

문제 링크

오랜만에 queue를 이용해서 풀이할 수 있는 문제를 만났다. 간단한 문제인데, list의 가장 왼쪽항을 빼고 다시 가장 우측항으로 옮기며 간단한 연산을 해주는 문제였다.

나의 풀이

from collections import deque

t = 10
for tc in range(1, t+1):
    tc_num = int(input())
    nums = deque(map(int, input().split()))
    i = 1
    while 0 not in nums:
        e = nums.popleft()-i
        nums.append(e if e > 0 else 0)
        if i == 5:
            i = 1
        else:
            i += 1

    print(f"#{tc_num}", end=" ")
    for num in nums:
        print(num, end=" ")
    print("")

© 2021. All rights reserved.