-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathtask.go
More file actions
88 lines (68 loc) · 1.41 KB
/
task.go
File metadata and controls
88 lines (68 loc) · 1.41 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
const (
responseYes = "YES"
responseNo = "NO"
)
func main() {
input, err := getInputData()
if err != nil {
showError(err)
}
var s, t string
input.Scan()
s = strings.TrimSpace(input.Text())
input.Scan()
t = strings.TrimSpace(input.Text())
fmt.Println(solution(s, t))
}
func solution(s, t string) string {
if len(s) != len(t) {
return responseNo
}
sToT := make(map[string]string)
tToS := make(map[string]string)
for i := 0; i < len(s); i++ {
sL := string(s[i])
tL := string(t[i])
if sToT[sL] == "" && tToS[tL] == "" {
sToT[sL] = tL
tToS[tL] = sL
}
if sToT[sL] != tL || tToS[tL] != sL {
return responseNo
}
}
return responseYes
}
// getInputData подготовка входных данных
func getInputData() (scan *bufio.Scanner, err error) {
var input *os.File
const maxCapacity = 1024 * 1024 * 10
input, err = getInputFromFile()
if err != nil {
showError(err)
}
scanner := bufio.NewScanner(input)
buf := make([]byte, maxCapacity)
scanner.Buffer(buf, maxCapacity)
scanner.Split(bufio.ScanLines)
return scanner, nil
}
// getInputFromFile получение ввода из файла
func getInputFromFile() (*os.File, error) {
file, err := os.Open("input.txt")
if err != nil {
return nil, err
}
return file, nil
}
// showError вывод ошибки
func showError(err interface{}) {
panic(err)
}