CodeUp/코드업-1420-python

cosmos·2021년 4월 1일
2
post-thumbnail

문제📖

풀이🙏

  • 민준이는 정신을 늦게 차렸다.
  • 첫째 줄에 n(3~50)이 입력된다.
  • 둘째 줄 부터 n+1행까지 친구의 이름과 점수가 공백으로 분리되어 입력된다.
  • 세 번째로 높은 학생의 이름을 출력한다.
    -> sorted + key, lambda + reverse + indexing으로 구현하였다.

코드💻

# codeup, 1420 : 3등 찾기, python3
import sys

def sort_score(n):
    student = []

    for i in range(n):
        name, score = input().split()
        score = int(score)
        student.append([name, score])
    
    result = sorted(student, key = lambda x : x[1], reverse = True)
    
    return result[2][0]
    
n = int(sys.stdin.readline())
    
print(sort_score(n))

결과😎

출처 && 깃허브📝

https://codeup.kr/problem.php?id=1420
github

0개의 댓글