結果
| 問題 |
No.79 過小評価ダメ・ゼッタイ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-03-11 18:34:24 |
| 言語 | Go (1.23.4) |
| 結果 |
AC
|
| 実行時間 | 249 ms / 5,000 ms |
| コード長 | 1,136 bytes |
| コンパイル時間 | 12,402 ms |
| コンパイル使用メモリ | 235,448 KB |
| 実行使用メモリ | 8,192 KB |
| 最終ジャッジ日時 | 2024-06-26 08:25:02 |
| 合計ジャッジ時間 | 15,321 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
package main
import (
"fmt"
"strconv"
"strings"
)
// エントリポイント
func main() {
input1 := 0
fmt.Scan(&input1)
in := ""
inAry := make([]string, 0)
for i := 0; i < input1; i++ {
fmt.Scan(&in)
inAry = append(inAry, in)
}
// 配列からスペース区切りの文字列に変換
input2 := strings.Join(inAry, " ")
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{}
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)
}