結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 1 ms
6,816 KB
testcase_03 AC 1 ms
6,816 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 WA -
testcase_06 RE -
testcase_07 RE -
testcase_08 WA -
testcase_09 RE -
testcase_10 RE -
testcase_11 WA -
testcase_12 RE -
testcase_13 RE -
testcase_14 WA -
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 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

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 {
	iUserCount, _ := strconv.Atoi(userCount)

	// 配列のサイズを変数で指定することはできないため、スライスを使用する。
	// 配列の定義 voteList := [iUserCount]int{}
	// エラー non-constant array bound iUserCount
	voteList := make([]int, iUserCount)

	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(iUserCount - maxIndex))))
}
0