새소식

Algorithm/코딩테스트

[goorm Level2] 성적표

  • -

문제

https://level.goorm.io/exam/171280/%EC%84%B1%EC%A0%81%ED%91%9C/quiz/1

설명

딕셔너리와 튜플을 주로 활용했다. 

 

코드

dict = {}
cnt_dict={}
n,m = map(int,input().split())
lst = []
for i in range(n):
	subject,score = map(int,input().split())
	lst.append((subject,score))
	
for x in lst:
	subject,socre = x[0],x[1]
	if subject in dict.keys():
		dict[subject]+=socre
		cnt_dict[subject]+=1
	else:
		dict[subject]=socre
		cnt_dict[subject]=1

for subject,score in dict.items():
	dict[subject]= score / cnt_dict[subject]
		

max_result = (0,0)
for sub,sc in dict.items():
	if sc > max_result[1]:
		max_result = (sub,sc)
	elif sc == max_result[1]:
		if sub > max_result[0]:
			continue
		else:
			max_result = (sub,sc)
print(max_result[0])

 

 

Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.