Skip to content

Commit

Permalink
[마라] 5430 AC #7
Browse files Browse the repository at this point in the history
  • Loading branch information
22sonamu committed Dec 22, 2022
1 parent 51d311e commit 3c71e8f
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions 마라/7주차/5430_AC.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from collections import deque

N = int(input())

def test(queue, function) :
rTime = 0
for c in function :
#R이 나올때마다 reverse 하면 비효율적 -> 횟수를 기록하여 홀수번 나왔을 경우에만 reverse
if c == "R" :
rTime += 1
if c == "D" :
if len(queue) == 0:
print("error")
return
#여태 R 이 짝수번 나왔으면 오른쪽에서 pop
if rTime % 2 == 0 :
queue.popleft()
#여태 R 이 홀수번 나왔으면 왼쪽에서 pop
else :
queue.pop()
#최종 R이 홀수번 나왔으면 reverse
if rTime % 2 == 1 :
queue.reverse()
print('['+','.join(list(queue))+']')
return



for _ in range(N) :
p = input()
n = int(input())
lstString = input()
tmp = lstString[1:-1].split(",")
lst = []
#공백 없애주기(리스트 크기가 0인경우를 위함)
for t in tmp :
if t != '' :
lst.append(t)
q = deque(lst)
test(q, p)

0 comments on commit 3c71e8f

Please sign in to comment.