본문 바로가기

코딩테스트 with PYTHON

[python] 코딩테스트 대비 - K번째 수

문제)

 

답안코드)

1
2
3
4
5
6
7
8
9
import sys
#sys.stdin=open("input.txt","rt")
T=int(input())#테스트 케이스 수 입력받기
for i in range(1,T+1):#케이스 수 만큼 loop
    N,s,e,k=map(int,input().split())#N s e k 입력받기
    box=list(map(int,input().split()))# N개의 숫자 list로 저장
    box=box[s-1:e]#s번째부터 e번째 까지 추출
    box.sort()#오름 차순 정렬
    print("#%d %d" %(i,box[k-1]))#출력 형식에 맞게 k번째 수 출력