57 lines
984 B
Go
57 lines
984 B
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
ArmyTypeImmune = 1 << iota
|
|
ArmyTypeInfection
|
|
)
|
|
|
|
func main() {
|
|
inp := StdinToStringSlice()
|
|
immune, infect := ParseInput(inp)
|
|
for _, v := range immune {
|
|
fmt.Println("++ ", v.immunities)
|
|
fmt.Println("-- ", v.weaknesses)
|
|
}
|
|
_, _ = immune, infect
|
|
}
|
|
|
|
func ParseInput(inp []string) ([]Army, []Army) {
|
|
var immune, infection []Army
|
|
var tp int
|
|
for _, v := range inp {
|
|
if v == "" {
|
|
continue
|
|
}
|
|
if v == "Immune System:" {
|
|
tp = ArmyTypeImmune
|
|
continue
|
|
} else if v == "Infection:" {
|
|
tp = ArmyTypeInfection
|
|
continue
|
|
}
|
|
switch tp {
|
|
case ArmyTypeImmune:
|
|
immune = append(immune, *NewArmy(v, tp))
|
|
case ArmyTypeInfection:
|
|
infection = append(infection, *NewArmy(v, tp))
|
|
}
|
|
}
|
|
return immune, infection
|
|
}
|
|
|
|
func StdinToStringSlice() []string {
|
|
var input []string
|
|
scanner := bufio.NewScanner(os.Stdin)
|
|
for scanner.Scan() {
|
|
input = append(input, scanner.Text())
|
|
}
|
|
return input
|
|
}
|