
[최종 코드]
import sys
n = int(sys.stdin.readline())
coor = []
for i in range(n):
a, b = map(int, input().split())
coor.append((a, b))
coor.sort(key=lambda x: (x[1], x[0]))
output_lines = [f'{x} {y}' for x, y in coor]
sys.stdout.write('\n'.join(map(str, output_lines)) + '\n')
[핵심 부분]
coor.sort(key=lambda x: (x[1], x[0]))
- lambda 함수를 이용해 (x, y)를 (y, x)로 바꾸기
output_lines = [f'{x} {y}' for x, y in coor]
sys.stdout.write('\n'.join(map(str, output_lines)) + '\n')
- 출력 형식 지정하여 조건에 맞게 출력하기
'백준 - 파이썬 > 단계별 - 13 (정렬)' 카테고리의 다른 글
| *[백준/파이썬] 18870번 좌표 압축 | enumerate함수 (0) | 2025.10.31 |
|---|---|
| *[백준/파이썬] 1181번 단어 정렬 | lambda함수 정렬키 (0) | 2025.10.22 |
| *[백준/파이썬] 11650번 좌표 정렬하기 (0) | 2025.10.22 |
| [백준/파이썬] 1427번 소트인사이드 (0) | 2025.10.22 |
| *[백준/파이썬] 10989번 수 정렬하기 3 | 계수 정렬 (Counting Sort) | 메모리초과 주의 (1) | 2025.10.22 |