結果
| 問題 |
No.79 過小評価ダメ・ゼッタイ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-03-11 18:26:58 |
| 言語 | Go (1.23.4) |
| 結果 |
AC
|
| 実行時間 | 246 ms / 5,000 ms |
| コード長 | 1,711 bytes |
| コンパイル時間 | 10,997 ms |
| コンパイル使用メモリ | 238,060 KB |
| 実行使用メモリ | 7,628 KB |
| 最終ジャッジ日時 | 2024-06-26 08:25:19 |
| 合計ジャッジ時間 | 13,876 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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))
}
/*
2018/03/11
yukicoder では、うまく動かないため、fmt.Scan を使う。
// 標準入力を読み込む。
func readLine() string {
// bufio.NewScannerの読み込める最大のバイト数は、
// 65,536(64 * 1024。bufioのMaxScanTokenSizeを参照)なので、
// bufio.NewScannerではなく、fmt.Scanを使用する。
// 参照
// https://qiita.com/tnoda_/items/b503a72eac82862d30c6
rdr := bufio.NewReaderSize(os.Stdin, 10000)
buf := make([]byte, 0, 10000)
for {
line, isPrefix, err := rdr.ReadLine() // ここで panic: EOF が発生する。
if err != nil {
panic(err)
}
buf = append(buf, line...)
if !isPrefix {
break
}
}
return string(buf)
}
*/
// 多数決で一番多いレベルを返す。
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)
}