본문 바로가기
백준 - 파이썬/단계별 - 13 (정렬)

*[백준/파이썬] 11650번 좌표 정렬하기

by miiinn 2025. 10. 22.

 

 

 

[최종 코드]

import sys
n =  int(sys.stdin.readline())

coor = []

for _ in range(n):
    a, b = map(int, input().split())
    coor.append((a, b))

# 정렬 로직 (기본 튜플 정렬: x좌표 우선, y좌표 차선)
coor.sort()

# 출력 최적화 (출력 형태 가공)
# coor의 각 튜플 (a, b)를 'a b' 형태의 문자열로 직접 변환하는 과정
output_lines = [f'{x} {y}' for x, y in coor]
sys.stdout.write('\n'.join(map(str, output_lines)) + '\n')

[핵심 부분]

# 출력 최적화 (출력 형태 가공)
# coor의 각 튜플 (a, b)를 'a b' 형태의 문자열로 직접 변환하는 과정
output_lines = [f'{x} {y}' for x, y in coor]
sys.stdout.write('\n'.join(map(str, output_lines)) + '\n')