結果

問題 No.21 平均の差
ユーザー yo-kondoyo-kondo
提出日時 2018-03-07 22:59:10
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 851 bytes
コンパイル時間 12,861 ms
コンパイル使用メモリ 222,996 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 05:18:11
合計ジャッジ時間 13,048 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 WA -
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

// エントリポイント
func main() {
	in := bufio.NewScanner(os.Stdin)

	// make([]string, 0) で空の []string を返す。
	texts := make([]string, 0)

	// 標準入力から複数行をすべて取得
	for in.Scan() {
		texts = append(texts, in.Text())
	}

	fmt.Println(average(texts))
}

// グループに分けて平均の最大、平均の最小の差を求める。
func average(str []string) string {

	// 数値の合計と、グループは使用しない。
	// total, _ := strconv.Atoi(str[0])
	// group, _ := strconv.Atoi(str[1])

	// 2番目から最後までを取り出す。
	num := str[2:]

	// []string のソート
	sort.Sort(sort.StringSlice(num))

	min, _ := strconv.Atoi(num[0])
	max, _ := strconv.Atoi(num[len(num)-1])
	return strconv.Itoa(max - min)
}
0