結果
問題 | No.21 平均の差 |
ユーザー | yo-kondo |
提出日時 | 2018-03-07 23:25:45 |
言語 | Go (1.22.1) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 873 bytes |
コンパイル時間 | 11,284 ms |
コンパイル使用メモリ | 226,456 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-04-15 06:06:41 |
合計ジャッジ時間 | 11,740 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,812 KB |
testcase_02 | AC | 1 ms
6,816 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,944 KB |
testcase_06 | AC | 2 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,940 KB |
ソースコード
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 { // 数値の合計 str[0] と、グループ str[1] は使用しない。 // 2番目から最後までを取り出す。 num := str[2:] // 数値に変換してからソートする intNum := make([]int,0) for _, v := range num { i, _ := strconv.Atoi(v) intNum = append(intNum, i) } sort.Sort(sort.IntSlice(intNum)) return strconv.Itoa(intNum[len(intNum)-1] - intNum[0]) }