์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ/BOJ_Python

[BOJ/Step12] 11650 : ์ขŒํ‘œ ์ •๋ ฌํ•˜๊ธฐ (Python)

NaNaRin๐Ÿ™ƒ 2021. 2. 19. 17:14

www.acmicpc.net/problem/11650

 

11650๋ฒˆ: ์ขŒํ‘œ ์ •๋ ฌํ•˜๊ธฐ

์ฒซ์งธ ์ค„์— ์ ์˜ ๊ฐœ์ˆ˜ N (1 ≤ N ≤ 100,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์—๋Š” i๋ฒˆ์ ์˜ ์œ„์น˜ xi์™€ yi๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (-100,000 ≤ xi, yi ≤ 100,000) ์ขŒํ‘œ๋Š” ํ•ญ์ƒ ์ •์ˆ˜์ด๊ณ , ์œ„์น˜๊ฐ€ ๊ฐ™์€ ๋‘ ์ ์€ ์—†๋‹ค.

www.acmicpc.net


1. ์ž…๋ ฅ๋ฐ›์€ n ํฌ๊ธฐ๋งŒํผ (x, y)๋ฅผ ๋ฆฌ์ŠคํŠธ xy์— ๋ฆฌ์ŠคํŠธ๋กœ ์ €์žฅ

2. ๋ฆฌ์ŠคํŠธ xy๋ฅผ ๋ฆฌ์ŠคํŠธ ์•ˆ์˜ ์ฒซ๋ฒˆ์งธ ์š”์†Œ, ๋‘๋ฒˆ์งธ ์š”์†Œ ์ˆœ์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ

 => ๋‚ด์žฅํ•จ์ˆ˜ sorted() ์‚ฌ์šฉ

3. ๋ฆฌ์ŠคํŠธ xy ์ถœ๋ ฅ

# 11650.py

import sys

n = int(input())
xy = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
xy = sorted(xy, key=lambda t: (t[0], t[1]))
for i in xy:
    print(i[0], i[1])