반응형
https://www.acmicpc.net/problem/5430
5430번: AC
각 테스트 케이스에 대해서, 입력으로 주어진 정수 배열에 함수를 수행한 결과를 출력한다. 만약, 에러가 발생한 경우에는 error를 출력한다.
www.acmicpc.net
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) +"]")
입출력 형태가 난해한게 가장 어려웠다.
댓글