ํ์ด
์ฃผ์ด์ง ๋ช ๋ น์ ๋ฐ๋ผ ๋ฌธ์์ด์ ์ฒ๋ฆฌํ๋ ๊ตฌํ๋ฌธ์ ์ด๋ค.
ํ์ด์ฌ์์ ๊ธฐ๋ณธ์ผ๋ก ์ ๊ณตํ๋ reverse ๋ pop ์ ํตํด ์ฝ๊ฒ ํ ์ ์๋ ๋ฌธ์ ์์ง๋ง, ์๊ฐ์ด๊ณผ๋ก ์ธํด ๋ค๋ฅธ ๋ฐฉ๋ฒ ์ฐพ์์ผํ๋ค.
๋ฐฉ๋ฒ์ ์๊ฐ๋ณด๋ค ๊ฐ๋จํ๋ค. ๋ช ๋ น์ด ์์์ ๋ฐ๋ผ์ ๋ฌธ์์ด์ ์ข์ธก ํน์ ์ฐ์ธก์ด ์ผ๋ง๋ ์ ๊ฑฐ๋ ๊ฒ์ธ์ง ๋ฏธ๋ฆฌ ํ์ ์ ํ ํ ์ธ๋ฑ์ฑ์ ํตํด ํ๋ฉด๋๋ค.
์์ค์ฝ๋
import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
p = input().rstrip()
p.replace('RR', '')
n = int(input())
x = input().rstrip()[1:-1].split(',')
l, r, b = 0, 0, True
for c in p:
if c == 'R':
b = not b
elif c == 'D':
if b:
l += 1
else:
r += 1
if l+r > n:
print('error')
else:
x = x[l:n-r]
if b:
x = ','.join(x)
else:
x = ','.join(x[::-1])
print(f'[{x}]')