-
Notifications
You must be signed in to change notification settings - Fork 27
/
384.go
71 lines (64 loc) · 1.22 KB
/
384.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
70
71
// UVa 384 - Slurpys
package main
import (
"fmt"
"os"
"strings"
)
func isSlump(s string) int {
if !strings.HasPrefix(s, "D") && !strings.HasPrefix(s, "E") || !strings.HasPrefix(s[1:], "F") {
return 0
}
idx := 2
for s[idx] == 'F' {
idx++
}
if s[idx] == 'G' {
return idx + 1
}
if len1 := isSlump(s[idx:]); len1 != 0 {
return idx + len1
}
return 0
}
func isSlimp(s string) int {
if strings.HasPrefix(s, "AH") {
return 2
}
if strings.HasPrefix(s, "AB") {
if len1 := isSlimp(s[2:]); len1 != 0 && s[2+len1] == 'C' {
return 3 + len1
}
return 0
}
if len1 := isSlump(s[1:]); len1 != 0 && s[1+len1] == 'C' {
return 2 + len1
}
return 0
}
func isSlurpy(s string) bool {
if len1 := isSlimp(s); len1 != 0 {
if len2 := isSlump(s[len1:]); len2 != 0 {
return len1+len2 == len(s)
}
return false
}
return false
}
func main() {
in, _ := os.Open("384.in")
defer in.Close()
out, _ := os.Create("384.out")
defer out.Close()
var kase int
var line string
fmt.Fprintln(out, "SLURPYS OUTPUT")
for fmt.Fscanf(in, "%d", &kase); kase > 0; kase-- {
if fmt.Fscanf(in, "%s", &line); isSlurpy(line) {
fmt.Fprintln(out, "YES")
} else {
fmt.Fprintln(out, "NO")
}
}
fmt.Fprintln(out, "END OF OUTPUT")
}