結果
| 問題 |
No.79 過小評価ダメ・ゼッタイ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-03-11 14:02:19 |
| 言語 | Go (1.23.4) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,533 bytes |
| コンパイル時間 | 12,377 ms |
| コンパイル使用メモリ | 242,016 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-15 00:13:38 |
| 合計ジャッジ時間 | 11,435 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 3 |
| other | AC * 9 WA * 2 RE * 11 |
ソースコード
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))))
}