Created
September 23, 2014 03:47
-
-
Save WilliamHester/86d473c369ed3641c0f0 to your computer and use it in GitHub Desktop.
Politics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
var n int | |
var m int | |
for fmt.Scanln(&n, &m); n > 0; fmt.Scanln(&n, &m) { | |
names := make([]string, 0, 100000) | |
cmap := make(map[string][]string) | |
for i := 0; i < n; i++ { | |
var name string | |
fmt.Scanln(&name) | |
names = append(names, name) | |
cmap[name] = make([]string, 0, 100) | |
} | |
for i := 0; i < m; i++ { | |
var supporter, candidate string | |
fmt.Scanln(&supporter, &candidate) | |
var sl, ok = cmap[candidate] | |
if ok { | |
if len(sl) < cap(sl) { | |
cmap[candidate] = append(cmap[candidate], supporter) | |
} else { | |
// sl2 := make([]string, 0, cap(sl)) | |
// sl2[0] = supporter | |
cmap[candidate] = append(cmap[candidate], supporter) | |
names = append(names, candidate) | |
} | |
} else { | |
names = append(names, candidate) | |
cmap[candidate] = make([]string, 0, 100) | |
cmap[candidate] = append(cmap[candidate], supporter) | |
} | |
} | |
for _, name := range names { | |
for _, candidate := range cmap[name] { | |
fmt.Println(candidate) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment