백준 11650 좌표 정렬하기 (파이썬)


11650 좌표 정렬하기 문제 바로가기


접근방식

  • x 좌표를 토대로 정렬을 해야하고 x 좌표가 같다면 y 좌표를 비교해야하는 문제이다.
  • sort()함수를 사용했더니 원하는 대로 정렬되었다.

파이썬 코드

import sys

n = int(sys.stdin.readline())
coordinates = []

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

coordinates.sort()
for xy in coordinates:
    print(xy[0],xy[1])





© 2020.09. by 다로

Powered by theorydb