[Python] 백준 1205번 - 등수 구하기

유빈·2025년 1월 13일
0

Algorithms

목록 보기
25/35
post-thumbnail

백준 문제집 PS

ses0028님의 "IT기업 및 대기업 계열사 코테보면서 비슷했던 문제들(지속적으로 업데이트 중)"

이번 방학 2달동안 골드 3 (81문제)까지 다 푸는 것이 목표입니다.

25.01.13 - 실버 4 1문제
(17/81문제)

문제문제 제목문제 티어문제 링크
1205등수 구하기실버 4https://www.acmicpc.net/problem/1205


🔗 문제 링크

백준 1205번: 등수 구하기


⏰ 소요된 시간

20분



🛡️ 난이도

실버 4



✨ 수도 코드

1. 문제 이해


2. 코드 분석

input = open(0).readline

N, t_score, P = map(int, input().split())

if N == 0:
    print(1)
    exit()
else:
    scores = sorted(list(map(int, input().split())), reverse=True)

if t_score in scores:
    for i in range(N):
        if scores[i] < t_score:
            print(scores.index(t_score) + 1)
            exit()
        elif i == N-1 and scores[N-1] == t_score:
            if N >= P:
                print(-1)
            else:
                print(scores.index(t_score) + 1)
                exit()
else:
    for i in range(N):
        if scores[i] < t_score and i <= P:
            print(i+1)
            exit()
    if N < P:
        print(N+1)
        exit()
    print(-1)

변수 정리

N: 리스트에 있는 점수의 개수
t_score: 태수의 새로운 점수
P: 랭킹 리스트에 올라갈 수 있는 점수의 개수
scores: 내림차순으로 정렬된 점수들 리스트


반례들을 모두 고려해서 코드를 작성하자.



profile
🌱

0개의 댓글