✔ 풀이를 위한 아이디어
✔ 코드
import sys
T = int(sys.stdin.readline())
for _ in range(T):
command = sys.stdin.readline().strip()
N = int(sys.stdin.readline())
num_string = sys.stdin.readline().strip()
nums = []
tmp = 1
for i in range(1, len(num_string)-1):
if num_string[i+1] == ',' or num_string[i+1] == ']':
nums.append(int(num_string[tmp:i+1]))
tmp = i+2
start = 0
end = N-1
reverse = 0
error = 0
for i in range(len(command)):
if command[i] == 'R':
reverse = 1 - reverse
elif command[i] == 'D':
if start > end:
error = 1
break
if reverse == 0:
start += 1
elif reverse == 1:
end -= 1
if error:
print("error")
elif start > end:
print("[]")
elif reverse == 0:
print("[{}".format(nums[start]), end="")
for i in range(start+1, end+1):
print(",{}".format(nums[i]), end="")
print("]")
elif reverse == 1:
print("[{}".format(nums[end]), end="")
for i in range(end-1, start-1, -1):
print(",{}".format(nums[i]), end="")
print("]")
처음으로 풀어본 백준 골드 문제!
✔ 관련 개념