結果

問題 No.79 過小評価ダメ・ゼッタイ
ユーザー yo-kondoyo-kondo
提出日時 2018-03-11 17:50:43
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 960 bytes
コンパイル時間 11,380 ms
コンパイル使用メモリ 223,372 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 01:08:15
合計ジャッジ時間 12,284 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main

import (
	"fmt"
	"strconv"
	"strings"
)

// エントリポイント
func main() {
	input1 := ""
	fmt.Scan(&input1)
	input2 := ""
	fmt.Scan(&input2)

	fmt.Println(majorityVote(input1, input2))
}

// 多数決で一番多いレベルを返す。
func majorityVote(userCount string, vote string) string {
	const maxLevel = 6
	_ = userCount

	// 配列のサイズを変数で指定することはできないため、スライスを使用する。
	// 例)
	//   int := 10
	//   voteList := [i]int{}
	// エラー)
	//   non-constant array bound i
	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(maxIndex + 1)
}
0