ํฐ์คํ ๋ฆฌ ๋ทฐ
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()
'algorithm > swea' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[swea] 4861. ํ๋ฌธ / python ํ์ด์ฌ (0) | 2021.04.09 |
---|---|
[swea] 2805. ๋์๋ฌผ ์ํํ๊ธฐ / python ํ์ด์ฌ (0) | 2021.04.08 |
[swea] 1220. Magnetic / python ํ์ด์ฌ (0) | 2021.04.08 |
[swea] 1219. ๊ธธ์ฐพ๊ธฐ / python ํ์ด์ฌ (1) | 2021.04.08 |
[swea] 4869. ์ข ์ด๋ถ์ด๊ธฐ / python ํ์ด์ฌ (0) | 2021.04.08 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
TAG
- swea
- ํ๋ก๊ทธ๋๋จธ์ค
- merge์๋ฌ
- ํ์ด์ฌ
- 17406 ๋ฐฐ์ด๋๋ฆฌ๊ธฐ4
- react
- ์๊ณ ๋ฆฌ์ฆ
- dfs
- 21609 ์์ด ์คํ๊ต
- ๊ธฐ์ง๊ตญ์ค์น
- Python
- ๋ฐฑ์ค
- ์ผ์ฑ์ฝํ
- 2018 ์นด์นด์ค ๊ณต์ฑ
- ์ผ์ฑ๊ธฐ์ถ
- 2579 ๊ณ๋จ์ค๋ฅด๊ธฐ
- BFS
- 20056 ๋ง๋ฒ์ฌ ์์ด์ ํ์ด์ด๋ณผ
- 20057 ๋ง๋ฒ์ฌ ์์ด์ ํ ๋ค์ด๋
- merge ์๋ฌ
- ๋ณด์์ผํ
- git ๋ฏธ๋ฌ๋ง
- ๋ธ๋ฃจํธํฌ์ค
- dp
- ์์ด๋๋ง์๊ธฐ
์ต๊ทผ์ ์ฌ๋ผ์จ ๊ธ
- Total
- Today
- Yesterday
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ