package main import ( "bufio" "fmt" "math" "os" "strconv" "strings" ) // 標準入力を読み込む。 func readLine() string { // bufio.NewScannerの読み込める最大のバイト数は、65,536(64 * 1024。bufioのMaxScanTokenSizeを参照)なので、 // bufio.NewScannerではなく、bufio.NewReaderSizeを使用する。 rdr := bufio.NewReaderSize(os.Stdin, 10000) buf := make([]byte, 0, 10000) for { l, p, e := rdr.ReadLine() if e != nil { panic(e) } buf = append(buf, l...) if !p { break } } return string(buf) } // エントリポイント func main() { input1 := readLine() input2 := readLine() fmt.Println(majorityVote(input1, input2)) } // 多数決で一番多いレベルを返す。 func majorityVote(userCount string, vote string) string { const maxLevel = 6 _ = userCount // 配列のサイズを変数で指定することはできないため、スライスを使用する。 // 配列の定義 voteList := [iUserCount]int{} // エラー non-constant array bound iUserCount 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(int(math.Abs(float64(maxIndex + 1)))) }