DHistory
[Baekjoon] Sort - 나이순 정렬 본문
문제
10814번: 나이순 정렬
온라인 저지에 가입한 사람들의 나이와 이름이 가입한 순서대로 주어진다. 이때, 회원들을 나이가 증가하는 순으로, 나이가 같으면 먼저 가입한 사람이 앞에 오는 순서로 정렬하는 프로그램을
www.acmicpc.net
풀이
import sys
n = int(sys.stdin.readline().rstrip())
people = []
for i in range(n):
age, name = sys.stdin.readline().rstrip().split()
people.append([int(age), name, i])
def solution(people):
return sorted(people, key=lambda x: (x[0], x[2]))
for age, name, _ in solution(people):
print(age, name, end='\n')
채점 결과
'Computer Science > Algorithm' 카테고리의 다른 글
[Baekjoon] Sort - 11004 K 번째 수 (0) | 2023.09.08 |
---|---|
[Baekjoon] Sort - 10815 숫자 카드 (0) | 2023.09.08 |
[Baekjoon] Sort - 11650 좌표 정렬하기 (0) | 2023.09.08 |
[Baekjoon] Sort - 1181 단어 정렬 (0) | 2023.09.08 |
[Baekjoon] Sort - 2751 수 정렬하기 2 (0) | 2023.09.08 |