結果
問題 |
No.79 過小評価ダメ・ゼッタイ
|
ユーザー |
|
提出日時 | 2018-03-11 12:49:36 |
言語 | Go (1.23.4) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,196 bytes |
コンパイル時間 | 12,512 ms |
コンパイル使用メモリ | 236,880 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-15 00:12:42 |
合計ジャッジ時間 | 13,197 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 RE * 10 |
ソースコード
package main import ( "bufio" "fmt" "math" "os" "strconv" "strings" ) // エントリポイント func main() { in := bufio.NewScanner(os.Stdin) // アンケートに回答するユーザー数 in.Scan() input1 := in.Text() // 各ユーザーの回答したレベル in.Scan() input2 := in.Text() 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)))) }