File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ import sys
2+ from collections import deque
3+
4+ input = sys .stdin .readline
5+
6+
7+ def AC ():
8+ p = input ().strip () # 수행할 함수
9+ n = int (input ()) # 배열 크기
10+ nums = input ().strip () # 배열 입력
11+
12+ # 배열 처리
13+ if nums == "[]" :
14+ nums = deque ()
15+ else :
16+ nums = deque (map (int , nums [1 :- 1 ].split ("," )))
17+
18+ reverse = False # 뒤집기 플래그
19+ for command in p :
20+ if command == "R" :
21+ reverse = not reverse # R이 나올 때마다 뒤집기 상태 토글
22+ elif command == "D" :
23+ if not nums : # 비어있는 경우 에러 출력
24+ print ("error" )
25+ return
26+ if reverse : # 뒤집힌 상태라면 뒤에서 제거
27+ nums .pop ()
28+ else : # 그렇지 않다면 앞에서 제거
29+ nums .popleft ()
30+
31+ # 최종 출력
32+ if reverse :
33+ nums .reverse () # 필요시 뒤집기
34+ print ("[" + "," .join (map (str , nums )) + "]" )
35+
36+
37+ # 테스트 케이스 처리
38+ T = int (input ()) # 테스트 케이스 수
39+ for _ in range (T ):
40+ AC ()
You can’t perform that action at this time.
0 commit comments