ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90

๐Ÿšฉ ํ(queue)

 

thinking

๋”ฑ ๋ด๋„ ํ๋ผ ํ๋กœ ํ’€์—ˆ๋‹ค. 

๋งจ ์•ž์˜ ์›์†Œ ๋นผ์„œ ๋‹ค์‹œ ๋’ค์— ๋ถ™์ด๋ฉด์„œ ์ˆซ์ž ๊ฐ์†Œ์‹œํ‚ค๋‹ค 0๋ณด๋‹ค ์ž‘์•„์ง€๋ฉด ๋ฐ˜๋ณต๋ฌธ ๋น ์ ธ๋‚˜์˜ค๋„๋ก ์กฐ๊ฑด ์„ค์ •ํ•จ

 

์ฝ”๋“œ1 - ํŒŒ์ด์ฌ ๋ฆฌ์ŠคํŠธ ๋ฐฉ๋ฒ• ( queue.pop(0) )

T = 10
for t in range(1, T+1):
    tc = int(input())
    queue = list(map(int, input().split()))

    i = 1
    while True:
        if i > 5:
            i = 1
        t = queue.pop(0) - i
        if t <= 0:
            queue.append(0)
            break
        queue.append(t)
        i += 1

    print("#{} {} {} {} {} {} {} {} {}".format(tc, *queue))

 

์ฝ”๋“œ2 - deque ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ฐฉ๋ฒ•

import collections


T = 10
for t in range(1, T+1):
    tc = int(input())
    queue2 = collections.deque(list(map(int, input().split())), maxlen=8)

    i = 1
    while True:
        if i > 5:
            i = 1
        t = queue2.popleft() - i
        if t <= 0:
            queue2.append(0)
            break
        queue2.append(t)
        i += 1

    print("#{}".format(tc), end=" ")
    for q in queue2:
        print("{}".format(q), end=" ")
    print()
    # ์ถœ๋ ฅํ˜•ํƒœ๋Š” ์—ฌ๋Ÿฌ๊ฐ€์ง€๋กœ ํ•  ์ˆ˜ ์žˆ๋‹ค.
    # print("#{}".format(tc), end=" ")
    # print(*queue2, end=" ")
    # print()

 

๋Œ“๊ธ€