結果

問題 No.79 過小評価ダメ・ゼッタイ
ユーザー yo-kondoyo-kondo
提出日時 2018-03-11 14:12:18
言語 Go
(1.22.1)
結果
RE  
実行時間 -
コード長 1,625 bytes
コンパイル時間 11,375 ms
コンパイル使用メモリ 225,288 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 01:03:30
合計ジャッジ時間 12,301 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 4 ms
6,820 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 3 ms
6,944 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 3 ms
6,944 KB
testcase_19 WA -
testcase_20 AC 3 ms
6,944 KB
testcase_21 RE -
testcase_22 WA -
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 3 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

// 標準入力を読み込む。
func readLine() string {
	// bufio.NewScannerの読み込める最大のバイト数は、
	// 65,536(64 * 1024。bufioのMaxScanTokenSizeを参照)なので、
	// bufio.NewScannerではなく、bufio.NewReaderSizeを使用する。
	// 参照
	// https://qiita.com/tnoda_/items/b503a72eac82862d30c6
	rdr := bufio.NewReaderSize(os.Stdin, 10000)
	buf := make([]byte, 0, 10000)
	for {
		line, isPrefix, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, line...)
		if !isPrefix {
			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))))
}
0