저번엔 deque로 뽑았지만 요번엔 투포인터
import sys
input = sys.stdin.readline
for test in range(int(input())):
p = input().rstrip()
n = int(input())
xi = input().rstrip()[1:-1].split(',')
if not n and 'D' in p:
print('error')
continue
reverse_x = 0
left = 0
right = len(xi)-1
for command in p:
if command == 'R':
reverse_x ^= 1
else:
if left <= right:
if reverse_x:
right -= 1
else:
left += 1
else:
print('error')
break
else:
if reverse_x:
print(f"[{','.join(xi[left:right+1][::-1])}]")
else:
print(f"[{','.join(xi[left:right+1])}]")
'practivceAlgorithm > 백준' 카테고리의 다른 글
[백준][Python] 2002 추월 (0) | 2021.09.03 |
---|---|
[백준][Python] 21966 (중략) (0) | 2021.09.03 |
[백준][Python] 2579 계단오르기 (0) | 2021.09.03 |
[백준][Python] 2667 단지번호붙이기 (0) | 2021.09.03 |
[백준][Python] 1992 쿼드트리 (0) | 2021.09.03 |