티스토리 뷰
📖 question
https://www.acmicpc.net/problem/5635
5635번: 생일
어떤 반에 있는 학생들의 생일이 주어졌을 때, 가장 나이가 적은 사람과 가장 많은 사람을 구하는 프로그램을 작성하시오.
www.acmicpc.net
✍️ answer
n = int(input())
studentList = []
for _ in range(n):
student = input().split() # 입력을 리스트로 받음
student[1:] = list(map(int, student[1:]))
studentList.append(student) # 미리 정의한 리스트에 리스트를 넣으면 이중 리스트가 됨
studentList.sort(key=lambda student: (student[3], student[2], student[1]))
# 내림차순 다중 조건으로 정리하는 함수
# 일,월,년 순서이므로 기준을 뒤에서부터 정함
print(studentList[-1][0]) # 제일 어린 사람
print(studentList[0][0]) # 제일 나이 든 사람
'Python > BAEKJOON' 카테고리의 다른 글
2444 별 찍기 - 7 (0) | 2022.06.06 |
---|---|
2069 최대공약수와 최소공배수 (0) | 2022.06.05 |
2443 별 찍기 - 6 (0) | 2022.06.03 |
10833 사과 (0) | 2022.06.02 |
10984 내 학점을 구해줘 (0) | 2022.06.01 |
댓글