๐๏ธ Algorithm/๐ฉ ๋ฐฑ์ค
๐ฉ [๋ฐฑ์ค] [Python] [Silver2] 1406๋ฒ_์๋ํฐ
Dbswnstjd
2023. 3. 9. 20:38
๋ฌธ์
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))))
์คํ์ด๋ผ๋ ์๋ฃ๊ตฌ์กฐ๋ฅผ ์ฌ์ฉํ๊ฒ ๋๋๋ฐ ์ด๋ฌํ ๋ฐฉ์์ ์๊ฐ์ง๋ ๋ชปํ์๋ค.
์คํ์ ํน์ฑ์ ๋งค์ฐ ์ ์ด๋ฆด ์ ์๋ ๋ฌธ์ ์ด๋ค.