-
[백준] 5430번: AC (Python)Algorithm PS👩🏻💻/백준 2023. 6. 28. 17:05
1. 문제 링크
https://www.acmicpc.net/problem/5430
5430번: AC
각 테스트 케이스에 대해서, 입력으로 주어진 정수 배열에 함수를 수행한 결과를 출력한다. 만약, 에러가 발생한 경우에는 error를 출력한다.
www.acmicpc.net
2. 풀이 코드
- 출력 형태가 리스트가 아니라 string 형식이어서 뭐가 틀린지 찾느라 열받았던 문제^,,,
import sys input = sys.stdin.readline tc = int(input()) result = [] for _ in range(tc): cmds = input().rstrip() length = int(input()) stack = input().rstrip()[1:-1].split(',') flag = True if cmds.count('D') > length: result.append('error') else: if 'RR' in cmds: cmds = cmds.replace('RR', '') for i in range(len(cmds)): if cmds[i] == 'R': flag = not flag else:#'D' if flag: del stack[0] else: del stack[-1] if flag: result.append('[' + ','.join(stack) + ']') else: result.append('[' + ','.join(stack[::-1]) + ']') for k in result: print(k)
'Algorithm PS👩🏻💻 > 백준' 카테고리의 다른 글
[백준] 8980번: 택배(Python) (0) 2023.07.06 [백준] 19598번: 최소 회의실 개수(Python, 그리디) (0) 2023.07.05 [백준] 3079번: 입국심사(이분탐색, Python) (0) 2023.05.30 [백준] 20444번: 색종이와 가위(이분탐색, Python) (0) 2023.05.29 [백준] 2470번: 두 용액(Python, Binary Search) (0) 2023.05.29