結果
問題 |
No.79 過小評価ダメ・ゼッタイ
|
ユーザー |
|
提出日時 | 2018-03-11 18:41:58 |
言語 | Go (1.23.4) |
結果 |
AC
|
実行時間 | 245 ms / 5,000 ms |
コード長 | 1,004 bytes |
コンパイル時間 | 11,137 ms |
コンパイル使用メモリ | 221,196 KB |
実行使用メモリ | 7,956 KB |
最終ジャッジ日時 | 2024-06-26 08:25:33 |
合計ジャッジ時間 | 13,967 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
package main import ( "fmt" "strconv" ) // エントリポイント func main() { input1 := 0 fmt.Scan(&input1) in := "" input2 := make([]string, 0) for i := 0; i < input1; i++ { fmt.Scan(&in) input2 = append(input2, in) } fmt.Println(majorityVote(input1, input2)) } // 多数決で一番多いレベルを返す。 func majorityVote(userCount int, vote []string) string { const maxLevel = 6 _ = userCount // 配列のサイズを変数で指定することはできないため、スライスを使用する。 // 例) // int := 10 // voteList := [i]int{} // エラー) // non-constant array bound i voteList := [maxLevel]int{} for _, v := range vote { 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) }