-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathtask.go
69 lines (60 loc) · 1.09 KB
/
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
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"bufio"
"fmt"
"io"
"os"
"strings"
"unicode"
)
func main() {
s := strings.Builder{}
Solution(os.Stdin, &s)
fmt.Println(strings.TrimSpace(s.String()))
}
func Solution(r io.Reader, s *strings.Builder) {
scanner := bufio.NewScanner(r)
const bufCapacity = 100000000 // fix long string
buf := make([]byte, bufCapacity)
scanner.Buffer(buf, bufCapacity)
scanner.Scan()
aBuilder := strings.Builder{}
for _, symbol := range scanner.Text() {
if unicode.Is(unicode.White_Space, symbol) {
break
}
if symbol%2 == 0 {
aBuilder.WriteRune(symbol)
}
}
scanner.Scan()
bBuilder := strings.Builder{}
for _, symbol := range scanner.Text() {
if unicode.Is(unicode.White_Space, symbol) {
break
}
if symbol%2 == 0 {
bBuilder.WriteRune(symbol)
}
}
s.WriteString(compare(aBuilder.String(), bBuilder.String()))
}
func compare(a, b string) string {
if a == b {
return "0"
}
for i := 0; i < len(a); i++ {
if i == len(b) {
return "1"
}
if a[i] == b[i] {
continue
}
if a[i] < b[i] {
return "-1"
} else {
return "1"
}
}
return "-1"
}