새소식

Algorithm/코딩테스트

[goorm Level1] 출석부

  • -

문제

https://level.goorm.io/exam/159667/%EC%B6%9C%EC%84%9D%EB%B6%80/quiz/1

 

 

풀이방법

  • (이름,키) 쌍의 튜플을 attendance리스트에 넣어서 관리
  • attendance리스트를, lambda로 sort하는 문법을 사용

문법

sorted_list = sorted(my_list, key=lambda x: (x[0], x[1]))
  • key값에 비교 기준을 두 개를 넣으면, x[0]이 동일할 경우 x[1]을 비교한다

코드

n,k = map(int,input().split())
attendance = []
for _ in range(n):
	name,height = input().split()
	attendance.append((name,height))

attendance = sorted(attendance, key=lambda x: (x[0], x[1]))

x,y = attendance[k-1]
print(x,y)
Contents

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

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