๋ฌธ์
https://www.acmicpc.net/problem/1406
1406๋ฒ: ์๋ํฐ
์ฒซ์งธ ์ค์๋ ์ด๊ธฐ์ ํธ์ง๊ธฐ์ ์ ๋ ฅ๋์ด ์๋ ๋ฌธ์์ด์ด ์ฃผ์ด์ง๋ค. ์ด ๋ฌธ์์ด์ ๊ธธ์ด๊ฐ N์ด๊ณ , ์์ด ์๋ฌธ์๋ก๋ง ์ด๋ฃจ์ด์ ธ ์์ผ๋ฉฐ, ๊ธธ์ด๋ 100,000์ ๋์ง ์๋๋ค. ๋์งธ ์ค์๋ ์ ๋ ฅํ ๋ช ๋ น์ด์ ๊ฐ์
www.acmicpc.net
ํ์ด
import sys
stack_l = list(input())
stack_r = []
n = int(input())
for i in range(n):
command = sys.stdin.readline().split()
if command[0] == "L" and stack_l:
stack_r.append(stack_l.pop())
elif command[0] == "D" and stack_r:
stack_l.append(stack_r.pop())
elif command[0] == "B" and stack_l:
stack_l.pop()
elif command[0] == "P":
stack_l.append(command[1])
print("".join(stack_l + list(reversed(stack_r))))
์คํ์ด๋ผ๋ ์๋ฃ๊ตฌ์กฐ๋ฅผ ์ฌ์ฉํ๊ฒ ๋๋๋ฐ ์ด๋ฌํ ๋ฐฉ์์ ์๊ฐ์ง๋ ๋ชปํ์๋ค.
์คํ์ ํน์ฑ์ ๋งค์ฐ ์ ์ด๋ฆด ์ ์๋ ๋ฌธ์ ์ด๋ค.
'๐๏ธ Algorithm > ๐ฉ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ฉ [๋ฐฑ์ค] [Python] [Silver2] 5397๋ฒ_ํค๋ก๊ฑฐ (0) | 2023.03.13 |
---|---|
๐ฉ [๋ฐฑ์ค] [Python] [Gold5] 1717๋ฒ_์งํฉ์ ํํ (0) | 2023.03.10 |
๐ฉ [๋ฐฑ์ค] [Python] [Silver2] 1699๋ฒ_์ ๊ณฑ์์ ํฉ (0) | 2023.03.05 |
๐ฉ [๋ฐฑ์ค] [Python] [Silver1] 1080๋ฒ_ํ๋ ฌ (0) | 2023.03.01 |
๐ฉ [๋ฐฑ์ค] [Python] [Silver2] 11051๋ฒ_์ดํญ ๊ณ์ 2 (0) | 2023.02.27 |