-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10814.go
51 lines (44 loc) · 785 Bytes
/
10814.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
"strings"
)
var (
w = bufio.NewWriter(os.Stdout)
r = bufio.NewReader(os.Stdin)
)
// Member struct
type Member struct {
Name string
Age int
Register int
}
func main() {
defer w.Flush()
var N int
fmt.Fscanf(r, "%d\n", &N)
m := []Member{}
for i := 0; i < N; i++ {
var tm Member
s, _ := r.ReadString('\n')
s = strings.TrimSuffix(s, "\n")
split := strings.Split(s, " ")
tm.Age, _ = strconv.Atoi(split[0])
tm.Name = split[1]
tm.Register = i
m = append(m, tm)
}
sort.SliceStable(m, func(i, j int) bool {
return m[i].Register < m[j].Register
})
sort.SliceStable(m, func(i, j int) bool {
return m[i].Age < m[j].Age
})
for _, v := range m {
fmt.Fprintln(w, v.Age, v.Name)
}
}