1. deque로 직접회전
from collections import deque
for _ in range(10):
test = int(input())
arr = deque(list(map(int, input().split())))
cnt = 0
while arr[-1] > 0:
arr.rotate(-1)
arr[-1] -= cnt%5+1
cnt += 1
arr[-1] = 0
print(f'#{test}',*arr)
2. 포인터로 간접회전
for _ in range(10):
test = int(input())
arr = list(map(int, input().split()))
idx = -1
cnt = 0
while arr[idx] > 0:
idx += 1
idx %= 8
arr[idx] -= cnt % 5 + 1
cnt += 1
arr[idx] = 0
answer = arr[idx+1:] + arr[:idx+1]
print(f'#{test}', *answer)
'practivceAlgorithm > swexpertacademy' 카테고리의 다른 글
[SWEA][Python] 1220 magnetic (0) | 2021.08.27 |
---|---|
[SWEA][Python] 1226 미로1 (0) | 2021.08.25 |
[SWEA][Python] 1223 계산기2 (0) | 2021.08.24 |
[SWEA][Python] 5178 노드의 합 (0) | 2021.08.24 |
[SWEA][Python] 5177 이진힙 (0) | 2021.08.24 |