-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy path620.go
53 lines (47 loc) · 955 Bytes
/
620.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
// UVa 620 - Cellular Structure
package main
import (
"fmt"
"os"
"strings"
)
func dfs(line string) bool {
if len(line) == 0 {
return false
}
switch {
case len(line) == 1:
return line == "A"
case strings.HasPrefix(line, "B") && strings.HasSuffix(line, "A"):
return dfs(line[1 : len(line)-1])
case strings.HasSuffix(line, "AB"):
return dfs(line[:len(line)-2])
default:
return false
}
}
func solve(line string) string {
if dfs(line) {
switch {
case len(line) == 1:
return "SIMPLE"
case strings.HasPrefix(line, "B") && strings.HasSuffix(line, "A"):
return "MUTAGENIC"
case strings.HasSuffix(line, "AB"):
return "FULLY-GROWN"
}
}
return "MUTANT"
}
func main() {
in, _ := os.Open("620.in")
defer in.Close()
out, _ := os.Create("620.out")
defer out.Close()
var kase int
var line string
for fmt.Fscanf(in, "%d", &kase); kase > 0; kase-- {
fmt.Fscanf(in, "%s", &line)
fmt.Fprintln(out, solve(line))
}
}