結果

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

テストケース

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

ソースコード

diff #

package main

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

// エントリポイント
func main() {
	in := bufio.NewScanner(os.Stdin)
	// アンケートに回答するユーザー数
	in.Scan()
	input1 := in.Text()
	// 各ユーザーの回答したレベル
	in.Scan()
	input2 := in.Text()

	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