This commit is contained in:
Meutel 2017-12-22 20:01:43 +01:00
parent c5aea36afe
commit e22fddcde7

68
09dec/main.go Normal file
View File

@ -0,0 +1,68 @@
package main
import (
"bufio"
"fmt"
"os"
)
const (
GROUP = iota
GARB
IGN
)
var (
state int
group int
score int
)
func main() {
state = GROUP
sc := bufio.NewScanner(os.Stdin)
sc.Split(bufio.ScanRunes)
for sc.Scan() {
parse(sc.Text())
}
fmt.Println("SCORE:", score)
}
func parse(c string) {
fmt.Println(c)
if state == IGN {
state = GARB
} else {
switch c {
case ",":
if state == GROUP {
fmt.Println("sep group")
//score += group
}
case "{":
if state == GROUP {
fmt.Println("start group")
group++
}
case "}":
if state == GROUP {
fmt.Println("end group")
score += group
group--
}
case "<":
if state == GROUP {
state = GARB
}
case ">":
if state == GARB {
state = GROUP
}
case "!":
if state == GARB {
state = IGN
}
}
}
fmt.Println(state, group, score)
}