[백준 5430] Integer Lists

Jun Heo·2023년 3월 24일

문제 링크 : https://www.acmicpc.net/problem/5430

1. 코드

import sys
from collections import deque

t = int(input())

while t:
    p = sys.stdin.readline().rstrip()
    n = int(sys.stdin.readline())
    ilist = sys.stdin.readline().rstrip()
    
    if n == 0:
        ilist = []
    else:
        ilist = deque(ilist[1:-1].split(','))
        
    left = True
    err = False
    
    for f in p:
        if f == 'R':
            left = not left
        elif f == 'D':
            if not ilist:
                err = True
                break
            elif left:
                ilist.popleft()
            else:
                ilist.pop()
    
    if err:
        print("error")
    else:
        if not left:
            ilist.reverse()
        print('[' + ','.join(ilist) + ']')
    
    t -= 1

0개의 댓글