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

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

 

10814๋ฒˆ: ๋‚˜์ด์ˆœ ์ •๋ ฌ

์˜จ๋ผ์ธ ์ €์ง€์— ๊ฐ€์ž…ํ•œ ์‚ฌ๋žŒ๋“ค์˜ ๋‚˜์ด์™€ ์ด๋ฆ„์ด ๊ฐ€์ž…ํ•œ ์ˆœ์„œ๋Œ€๋กœ ์ฃผ์–ด์ง„๋‹ค. ์ด๋•Œ, ํšŒ์›๋“ค์„ ๋‚˜์ด๊ฐ€ ์ฆ๊ฐ€ํ•˜๋Š” ์ˆœ์œผ๋กœ, ๋‚˜์ด๊ฐ€ ๊ฐ™์œผ๋ฉด ๋จผ์ € ๊ฐ€์ž…ํ•œ ์‚ฌ๋žŒ์ด ์•ž์— ์˜ค๋Š” ์ˆœ์„œ๋กœ ์ •๋ ฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ๏ฟฝ

www.acmicpc.net


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

๐ŸŽจ Go

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

type userInfo struct {
	age int
	name string
}

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

	var users = make([]userInfo, n)
	for i:=0; i<n; i++ {
		fmt.Fscanln(reader, &users[i].age, &users[i].name)
	}

	sort.SliceStable(users, func(i,j int) bool {
		return users[i].age < users[j].age
	})

	for i:=0; i<n;i++ {
		fmt.Fprintln(writer, users[i].age, users[i].name)
	}
}
728x90
๋Œ“๊ธ€