結果

問題 No.79 過小評価ダメ・ゼッタイ
ユーザー yo-kondoyo-kondo
提出日時 2018-03-11 18:34:24
言語 Go
(1.22.1)
結果
AC  
実行時間 247 ms / 5,000 ms
コード長 1,136 bytes
コンパイル時間 13,033 ms
コンパイル使用メモリ 213,812 KB
実行使用メモリ 9,980 KB
最終ジャッジ日時 2023-09-08 15:22:22
合計ジャッジ時間 16,357 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
4,380 KB
testcase_01 AC 244 ms
7,924 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 247 ms
9,980 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 144 ms
7,944 KB
testcase_15 AC 62 ms
7,744 KB
testcase_16 AC 192 ms
7,916 KB
testcase_17 AC 54 ms
5,680 KB
testcase_18 AC 179 ms
7,924 KB
testcase_19 AC 129 ms
7,944 KB
testcase_20 AC 247 ms
7,800 KB
testcase_21 AC 6 ms
4,380 KB
testcase_22 AC 87 ms
7,916 KB
testcase_23 AC 230 ms
7,996 KB
testcase_24 AC 236 ms
7,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

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

	in := ""
	inAry := make([]string, 0)
	for i := 0; i < input1; i++ {
		fmt.Scan(&in)
		inAry = append(inAry, in)
	}

	// 配列からスペース区切りの文字列に変換
	input2 := strings.Join(inAry, " ")

	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{}

	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