// http://www.spoj.com/problems/HOMO/ package main import ( "bufio" "io" "os" "strconv" "strings" ) type List struct { Map map[int]int Homo int } func (l *List) Insert(n int) { if l.Map[n]++; l.Map[n] > 1 { l.Homo++ } } func (l *List) Delete(n int) { if l.Map[n] > 1 { l.Homo-- } if l.Map[n]--; l.Map[n] <= 0 { delete(l.Map, n) } } func (l List) IsHomo() bool { return l.Homo > 0 } func (l List) IsHetero() bool { return len(l.Map) > 1 } func Split(s string) (string, int) { i := strings.Index(s, " ") n, _ := strconv.Atoi(s[i+1:]) return s[:i], n } func (l List) Kind() string { homo, hetero := l.IsHomo(), l.IsHetero() switch { case homo && hetero: return "both" case hetero: return "hetero" case homo: return "homo" default: return "neither" } } func Homo(r io.Reader, w io.Writer) { scanner := bufio.NewScanner(r) scanner.Scan() // eat # of cases l := List{ Map: make(map[int]int), } for scanner.Scan() { s, n := Split(scanner.Text()) switch s { case "insert": l.Insert(n) case "delete": l.Delete(n) } io.WriteString(w, l.Kind()) io.WriteString(w, "\n") } } func main() { Homo(os.Stdin, os.Stdout) }