본문 바로가기
Problem Solving/SWEA

[SWEA|파이썬] 1230. [S/W 문제해결 기본] 8일차 - 암호문3 (D3)

by 청량리 물냉면 2023. 5. 19.
반응형
문제

https://tinyurl.com/2pf6lu89

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

 

🐍파이썬
T = 10
for test_case in range(1, T + 1):
    ans = 0
    input() #원본 암호문 길이
    code = list(input().split())    #원본 암호문
    input() #명령어의 개수
    command = list(input().split()) #명령어
    for i in range(len(command)):
        if command[i] == "I":
            x, y = int(command[i+1]), int(command[i+2])
            for j in range(y):  #y개 insert
                s = command[i+3+j]  #3번째 숫자부터 차례로
                code.insert(x+j, s) #x번째 수 뒤에 insert
        elif command[i] == "D":
            x, y = int(command[i+1]), int(command[i+2])
            code = code[:x]+code[x+y:]
        elif command[i] == "A":
            y = int(command[i+1])
            for j in range(y):
                code.append(command[i+2+j])
    print("#{} {}".format(test_case, ' '.join(code[:10])))
반응형