DHistory

[Baekjoon] Sort - 11650 좌표 정렬하기 본문

Computer Science/Algorithm

[Baekjoon] Sort - 11650 좌표 정렬하기

ddu0422 2023. 9. 8. 14:42

문제

 

11650번: 좌표 정렬하기

첫째 줄에 점의 개수 N (1 ≤ N ≤ 100,000)이 주어진다. 둘째 줄부터 N개의 줄에는 i번점의 위치 xi와 yi가 주어진다. (-100,000 ≤ xi, yi ≤ 100,000) 좌표는 항상 정수이고, 위치가 같은 두 점은 없다.

www.acmicpc.net

 

풀이

import sys

n = int(sys.stdin.readline().rstrip())
coordinates = []
for _ in range(n):
    x, y = map(int, sys.stdin.readline().rstrip().split())
    coordinates.append((x, y))


def solution(coordinates):
    return sorted(coordinates, key=lambda x: (x[0], x[1]))


for x, y in solution(coordinates):
    print(x, y, end='\n')

 

채점 결과