-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathtask.go
58 lines (48 loc) · 840 Bytes
/
task.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
53
54
55
56
57
58
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func main() {
var input *os.File
var bufStr string
var err error
var n int
input, err = getInputFromFile()
if err != nil {
showError(err)
}
// close file
defer func(input *os.File) {
_ = input.Close()
}(input)
scanner := bufio.NewScanner(input)
scanner.Split(bufio.ScanLines)
scanner.Scan()
bufStr = scanner.Text()
n, err = strconv.Atoi(bufStr)
if err != nil {
return
}
items := make(map[string]bool, n)
for i := 0; i < n; i++ {
scanner.Scan()
bufStr = scanner.Text()
if _, ok := items[bufStr]; !ok {
fmt.Println(bufStr)
items[bufStr] = true
}
}
}
func getInputFromFile() (*os.File, error) {
file, err := os.Open("input.txt")
if err != nil {
return nil, err
}
return file, nil
}
func showError(err interface{}) {
panic(err)
}