package main import ( "fmt" "strconv" "strings" ) // エントリポイント func main() { input1 := "" fmt.Scan(&input1) input2 := "" fmt.Scan(&input2) fmt.Println(majorityVote(input1, input2)) } // 多数決で一番多いレベルを返す。 func majorityVote(userCount string, vote string) string { const maxLevel = 6 _ = userCount // 配列のサイズを変数で指定することはできないため、スライスを使用する。 // 例) // int := 10 // voteList := [i]int{} // エラー) // non-constant array bound i voteList := [maxLevel]int{} sp := strings.Split(vote, " ") for _, v := range sp { index, _ := strconv.Atoi(v) voteList[index-1]++ } // 配列の中で一番大きい数値のインデックスを返す。 maxIndex := 0 maxNum := 0 for i := 0; i < len(voteList); i++ { if voteList[i] >= maxNum { maxIndex = i maxNum = voteList[i] } } return strconv.Itoa(maxIndex + 1) }