파이썬/코딩테스트

[코드업] 1등한 학생의 성적 - Python(파이썬)

대전집주인 2024. 3. 23. 16:04
728x90
SMALL

 

리스트 형식으로 값을 받아 공백으로 각자 배열을 만들어주었다. 첫번째 성적의 1등인 사람의 리스트 인덱스를 구하였고 인덱스 위치에 있는 값이 성적마다 등수가 몇등인지 구하였다. index의 경우 0부터 시작이라 +1을 해주었다.

 

n = int(input())    # 입력받을 값
result = []         # 이름을 입력받을 리스트
result1 = []        # 첫번째 성적
result2 = []        # 두번째 성적
result3 = []        # 세번째 성적
for i in range(n):
    data = list(map(str, input().split()))
    result.append(data[0])
    result1.append(int(data[1]))       
    result2.append(int(data[2]))
    result3.append(int(data[3]))

name_index = result1.index(max(result1))    # 첫번짹 성적 1등의 index구하기

# 각 과목 성적구하기
second_sort = sorted(result2)
third_sort = sorted(result3)
second_sort.reverse()
third_sort.reverse()
print(result[name_index], second_sort.index(result2[name_index]) + 1
      , third_sort.index(result3[name_index]) + 1)

 

728x90
LIST