ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ๋ฌธ์ œ

 

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

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

www.acmicpc.net


โœ๐Ÿป ํ’€์ด

๐ŸŽจ Go

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	var n int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanln(reader, &n)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var mat = make([][]int, n)
	for i := 0; i < n; i++ {
		mat[i] = make([]int, 2)
	}

	for i := 0; i < n; i++ {
		fmt.Fscanln(reader, &mat[i][0], &mat[i][1])
	}

	sort.Slice(mat, func(i, j int) bool {
		for idx := range mat[i] {
			if mat[i][idx] == mat[j][idx] {
				continue
			}
			return mat[i][idx] < mat[j][idx]
		}
		return false
	})

	for i := 0; i < n; i++ {
		fmt.Fprintf(writer, "%d %d\n", mat[i][0], mat[i][1])
	}
}
728x90
๋Œ“๊ธ€