반응형
https://www.acmicpc.net/problem/5430
import re
case = int(input())
for _ in range(case):
command = input()
n = int(input())
lst = input()[1:-1]
lst = list(re.sub(',',' ',lst).split())
reverse = False
front = 0
end = 0
error = False
for com in command:
if com == "R" : reverse = not reverse
else: # "D"
if front+end == n:
error = True
break
if reverse: end += 1
else: front += 1
if error:
print('error')
continue
ans = lst[front:n-end]
if reverse:
ans = ans[::-1]
print("["+ ','.join(ans) +"]")
입출력 형태가 난해한게 가장 어려웠다.
댓글