Based on the list of dungeon raids, find the top player in the guild 🙂
Example of input:
15
Stockade Shtukensia
Stockade Shtukensia
Stockade Shtukensia
Stockade Lucifer
Gnomeregan Shtukensia
Stockade Shtukensia
Deadmines Igroglaz
Stockade Pingi
Deadmines Pingi
Gnomeregan Terter
Gnomeregan Lucifer
Deadmines Terter
Stockade Terter
Deadmines Igroglaz
Gnomeregan Lucifer
Output should be:
Shtukensia : 1.00
Pingi : 1.00
Lucifer : 1.00
Lucifer : 1.00
Lucifer : 1.00
Top players:
Shtukensia
Code:
package main import ( "bufio" "fmt" "os" "strconv" "strings" ) func getNum(r *bufio.Reader) int { input, _ := r.ReadString('\n') input = strings.TrimSpace(input) n, _ := strconv.Atoi(input) return n } func getS(r *bufio.Reader) []string { input, _ := r.ReadString('\n') input = strings.TrimSpace(input) return strings.Split(input, " ") } func main() { r := bufio.NewReader(os.Stdin) runsN := getNum(r) // get number of dungeon runs (predefined) runsPerDung := make(map[string]float32) dungMap := make(map[string]bool) var dungs float32 // go through all input for i := 0; i < runsN; i++ { s := getS(r) dung := s[0] nick := s[1] // create list (slice) of all runs which we have if !dungMap[dung] { dungMap[dung] = true dungs++ } runsPerDung[nick] += 1 } for i, v := range runsPerDung { fmt.Printf("%s : %.2f\n", i, v/dungs) } fmt.Println("\nTop players: ") for i, v := range runsPerDung { if v/dungs >= 1.1 { fmt.Println(i) } } }