[백준/파이썬] 5397번

민정·2023년 7월 31일
0

[백준/파이썬]

목록 보기
154/245
post-thumbnail

📍백준 5397번 문제

https://www.acmicpc.net/problem/5397

코드

import sys

input = sys.stdin.readline

test_case = int(input())


for _ in range(test_case):
    pw = list(input().rstrip('\n'))
    left = []
    right = []
    i = 0
    for i in pw:
        if i == '<':
            if left:
                right.append(left.pop())
        elif i == '>':
            if right:
                left.append(right.pop())
        elif i == '-':
            if left:
                left.pop()
        else:
            left.append(i)
    left.extend(reversed(right))
    print(''.join(left))

풀이

백준 1406번과 같은 방식으로 풀면 된다 !

profile
パㅔバ6ㅇr 덤벼ㄹΓ :-0

0개의 댓글