53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"sort"
|
|
)
|
|
|
|
type Team struct {
|
|
Name string
|
|
Players []string
|
|
}
|
|
|
|
type League struct {
|
|
name string
|
|
Teams map[string]Team
|
|
Wins map[string]int
|
|
}
|
|
|
|
func (l *League) MatchResult(firstTeam string, firstScore int, secondTeam string, secondScore int) {
|
|
if _, ok := l.Teams[firstTeam]; ok {
|
|
return
|
|
}
|
|
if _, ok := l.Teams[secondTeam]; ok {
|
|
return
|
|
}
|
|
if firstScore == secondScore {
|
|
return
|
|
}
|
|
if firstScore > secondScore {
|
|
l.Wins[firstTeam]++
|
|
} else if secondScore > firstScore {
|
|
l.Wins[secondTeam]++
|
|
}
|
|
}
|
|
|
|
func (l League) Ranking() []string {
|
|
teamRanking := make([]string, 0, len(l.Wins))
|
|
for winsK := range l.Wins {
|
|
teamRanking = append(teamRanking, winsK)
|
|
}
|
|
sort.Slice(teamRanking, func(i, j int) bool {
|
|
return l.Wins[teamRanking[i]] < l.Wins[teamRanking[j]]
|
|
})
|
|
return teamRanking
|
|
}
|
|
|
|
func main() {
|
|
league := League{"newLeague", map[string]Team{}, map[string]int{"first": 1, "second": 2, "third": 6, "fourth": 3, "fifth": 4}}
|
|
league.MatchResult("third", 5, "second", 4)
|
|
fmt.Println(league)
|
|
fmt.Println(league.Ranking())
|
|
}
|