-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path13.py
55 lines (47 loc) · 1.1 KB
/
13.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# AC (https://www.acmicpc.net/problem/5430)
# "RDD"는 배열을 뒤집은 다음 처음 두 숫자를 버리는 함수
# 나의 정답
import sys
input = sys.stdin.readline
for _ in range(int(input())):
is_reversed = False
commands = input().rstrip()
first_idx = 0
last_idx = int(input())
num_string = input().rstrip()
queue = []
if num_string != "[]":
queue = list(map(int, num_string[1:-1].split(',')))
for c in commands:
if c == "R":
is_reversed = not is_reversed
continue
if is_reversed:
last_idx -= 1
else:
first_idx += 1
if first_idx <= last_idx:
if is_reversed:
print('[' + ','.join(map(str, queue[first_idx:last_idx][::-1])) + ']')
else:
print('[' + ','.join(map(str, queue[first_idx:last_idx])) + ']') # [1, 2]는 틀림. [1,2]는 맞음
else:
print("error")
# ==========================================================
# 4
# RDD
# 4
# [1,2,3,4]
# DD
# 1
# [42]
# RRD
# 6
# [1,1,2,3,5,8]
# D
# 0
# []
# [2,1]
# error
# [1,2,3,5,8]
# error