-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10867.go
52 lines (47 loc) · 829 Bytes
/
10867.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
52
package main
import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
"strings"
)
var (
w = bufio.NewWriter(os.Stdout)
r = bufio.NewReader(os.Stdin)
)
func main() {
defer w.Flush()
var N int
fmt.Fscanf(r, "%d\n", &N)
arr := makeSliceUnique(getInts())
sort.Slice(arr, func(i, j int) bool {
return arr[i] < arr[j]
})
for i := range arr {
fmt.Fprintf(w, "%d ", arr[i])
}
}
func getInts() []int {
s, _ := r.ReadString('\n')
s = strings.TrimSuffix(s, "\n")
t := strings.Fields(s)
res := make([]int, len(t))
for i := range t {
res[i], _ = strconv.Atoi(t[i])
}
return res
}
func makeSliceUnique(arr []int) []int {
res := make([]int, 0, len(arr))
d := make(map[int]struct{})
for i := range arr {
if _, ok := d[arr[i]]; ok {
continue
}
d[arr[i]] = struct{}{}
res = append(res, arr[i])
}
return res
}