우선 입력은 평소처럼 list형, int형 등으로 받아준다.
사실 구현은 어렵지 않은데, 테스트 케이스가 너무 많아서 눈알 아팠음...
각 명령어들마다 idx 값을 잘 조정하여서, 암호문 list에 잘 넣거나 빼기만 하면 됨!
import sys
sys.stdin = open("input.txt", "r")
T = 10
for test_case in range(1, T + 1):
n = int(input())
code = list(input().split())
x = int(input())
xcode = list(input().split())
ptr = 0
for i in range(x):
typ = xcode[ptr]
if typ == "I":
# 위치 선정
ptr += 1
j = int(xcode[ptr])
# 얼마나 삽입할 건지
ptr += 1
cnt = int(xcode[ptr])
for i in range(cnt):
ptr += 1
code.insert(j,xcode[ptr])
j += 1
ptr += 1
elif typ == "D":
ptr += 1
j = int(xcode[ptr])-1
ptr += 1
cnt = int(xcode[ptr])
for i in range(cnt):
del code[j]
ptr += 1
elif typ == "A":
ptr += 1
cnt = int(xcode[ptr])
for i in range(cnt):
ptr += 1
newcode = xcode[ptr]
code.append(newcode)
ptr += 1
print("#"+str(test_case),end=" ")
for i in range(10):
print(code[i],end=" ")
print()