1205 : 등수구하기

서희찬·2021년 11월 9일
0

백준

목록 보기
71/105

문제

코드

import sys 
input = sys.stdin.readline

n,score,p = map(int,input().split())

if(n<=0):
    print(1);exit(0)

arr = list(map(int,input().split()))
arr.append(score)
arr.sort(reverse=True) #내림차순으로 정렬 

idx = arr.index(score)+1 #스코어 인덱스 출력 #공동 등수라고 해도 앞에거 출력하기에 괜춘 

if idx>p:
    print(-1)
else :
    if n==p and arr[-1]==score:
        print(-1)
    else: 
        print(idx)

해설

내림차순으로 정렬전에 입력받은 점수를 arr에 넣어주고 내림차순으로 정렬해줬다.
그러고 인덱스값을 .index를 사용해서 찾아오는데 공동등수라고해도 앞에 요소를 먼저 출력하기에 괜찮다.
그리고 예외 처리를 진행해주었다.

profile
Carnegie Mellon University Robotics Institute | Research Associate | Developing For Our Lives, 세상에 기여하는 삶을 살고자 개발하고 있습니다

0개의 댓글

관련 채용 정보