Algorithm/SWEA

[SWEA - D3] 1225. μ•”ν˜Έμƒμ„±κΈ°

hello_u 2023. 5. 4. 14:40

 

λ‚˜μ˜ μ½”λ“œ 

from collections import deque
for _ in range(1, 11):
    t = int(input())
    arr = list(map(int,input().split()))
    deq = deque(arr)
    while 0 not in deq:
        for i in range(1,6):
            tmp = deq.popleft()
            if tmp-i <= 0:
                deq.append(0)
                break
            else:
                deq.append(tmp-i)
    print("#"+str(t) , end=" ")
    for x in deq:
        print(x , end=" ")
    print()

 

 

deque.popleft() κ°€ μ•„λ‹Œ κ·Έλƒ₯ list μ—μ„œ pop(0) ν–ˆμ–΄λ„ 됐닀.

 

λ°˜λ³΅λ¬Έμ„ μ‚¬μš©ν•΄μ„œ 리슀트 값을 좜λ ₯ν•˜λŠ”κ²Œ μ•„λ‹Œ * λ₯Ό μ΄μš©ν•˜μž 

 


λ§Œμ•½ *λ₯Ό μ‚¬μš©ν•˜λ©΄, μ΄λŠ” μ–ΈνŒ¨ν‚Ή(unpacking) μ—°μ‚°μžλ‘œ μž‘μš©ν•˜μ—¬, 

μ‹œν€€μŠ€ λ°μ΄ν„° νƒ€μž…에 μ €μž₯된 κ°’듀을 κ°κ° κ°œλ³„적인 μΈμžλ‘œ μ „λ‹¬ν•©λ‹ˆλ‹€. 

 

예λ₯Ό λ“€μ–΄, λ¦¬μŠ€νŠΈ(list)에 μ €μž₯된 κ°’듀을 print() ν•¨μˆ˜μ—μ„œ *λ₯Ό μ‚¬μš©ν•˜μ—¬ μΆœλ ₯ν•˜λ©΄, 

λ¦¬μŠ€νŠΈμ— μ €μž₯된 κ°’듀이 κ°œλ³„적인 μΈμžλ‘œ μ „λ‹¬λ˜μ–΄ μΆœλ ₯λ©λ‹ˆλ‹€.


λ‹€μŒμ€ λ¦¬μŠ€νŠΈμ— μ €μž₯된 κ°’듀을 *λ₯Ό μ‚¬μš©ν•˜μ—¬ μΆœλ ₯ν•˜λŠ” μ˜ˆμ‹œμž…λ‹ˆλ‹€.

my_list = [1, 2, 3]
print(*my_list)

# 좜λ ₯
1 2 3