На основе списка походов в данж найти топ игрока в гильдии 🙂
Пример ввода:
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
Пример вывода:
Igroglaz : 0.67
Pingi : 0.67
Terter : 1.00
Shtukensia : 1.67
Lucifer : 1.00
Top players:
Shtukensia
Код:
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) } } }