From 3c71e8fedbbbea6bd3e49756b7271572ceb6cf35 Mon Sep 17 00:00:00 2001 From: 22sonamu <22sonamu@naver.com> Date: Thu, 22 Dec 2022 21:25:17 +0900 Subject: [PATCH] =?UTF-8?q?[=EB=A7=88=EB=9D=BC]=205430=20AC=20#7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../7\354\243\274\354\260\250/5430_AC.py" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "\353\247\210\353\235\274/7\354\243\274\354\260\250/5430_AC.py" diff --git "a/\353\247\210\353\235\274/7\354\243\274\354\260\250/5430_AC.py" "b/\353\247\210\353\235\274/7\354\243\274\354\260\250/5430_AC.py" new file mode 100644 index 0000000..f707f15 --- /dev/null +++ "b/\353\247\210\353\235\274/7\354\243\274\354\260\250/5430_AC.py" @@ -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) \ No newline at end of file