結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
4,380 KB
testcase_01 AC 245 ms
7,764 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 246 ms
7,912 KB
testcase_06 AC 2 ms
4,504 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 143 ms
7,908 KB
testcase_15 AC 60 ms
5,664 KB
testcase_16 AC 184 ms
7,768 KB
testcase_17 AC 55 ms
5,652 KB
testcase_18 AC 177 ms
7,768 KB
testcase_19 AC 128 ms
7,912 KB
testcase_20 AC 249 ms
7,952 KB
testcase_21 AC 6 ms
4,380 KB
testcase_22 AC 85 ms
7,888 KB
testcase_23 AC 230 ms
7,816 KB
testcase_24 AC 238 ms
7,872 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))
}

// 多数決で一番多いレベルを返す。
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