結果

問題 No.79 過小評価ダメ・ゼッタイ
ユーザー yo-kondoyo-kondo
提出日時 2018-03-11 18:26:58
言語 Go
(1.22.1)
結果
AC  
実行時間 248 ms / 5,000 ms
コード長 1,711 bytes
コンパイル時間 11,568 ms
コンパイル使用メモリ 214,076 KB
実行使用メモリ 7,960 KB
最終ジャッジ日時 2023-09-08 15:22:40
合計ジャッジ時間 14,108 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
4,376 KB
testcase_01 AC 246 ms
7,832 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 248 ms
7,892 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 142 ms
7,912 KB
testcase_15 AC 61 ms
5,660 KB
testcase_16 AC 189 ms
7,908 KB
testcase_17 AC 59 ms
5,656 KB
testcase_18 AC 182 ms
7,868 KB
testcase_19 AC 131 ms
7,908 KB
testcase_20 AC 248 ms
7,956 KB
testcase_21 AC 7 ms
4,380 KB
testcase_22 AC 86 ms
7,900 KB
testcase_23 AC 226 ms
7,960 KB
testcase_24 AC 240 ms
7,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
}
0