본문 바로가기

알고리즘 문제풀이

Swea D2_11884 회전 Python Queue

내가 푼 코드, 파이썬이니까 append, pop이용함

T = int(input())
for tc in range(1,T+1):
    N, M = map(int,input().split())
    arr = list(map(int,input().split()))
    for _ in range(M):
        arr.append(arr.pop(0))
    print(f'#{tc} {arr[0]}')

 

다른 분이 푼 코드 (길이 150자)

T = int(input())
for tc in range(1, T+1):
    N, M = map(int, input().split())
    arr = list(map(int, input().split()))
 
    print(f'#{tc} {arr[M % N]}')