結果

問題 No.21 平均の差
ユーザー tokustokus
提出日時 2021-11-17 13:35:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 57 ms / 5,000 ms
コード長 1,359 bytes
コンパイル時間 2,179 ms
コンパイル使用メモリ 77,616 KB
実行使用メモリ 50,880 KB
最終ジャッジ日時 2023-08-25 00:56:50
合計ジャッジ時間 3,566 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
50,632 KB
testcase_01 AC 56 ms
50,724 KB
testcase_02 AC 53 ms
50,640 KB
testcase_03 AC 55 ms
50,644 KB
testcase_04 AC 55 ms
50,704 KB
testcase_05 AC 54 ms
50,708 KB
testcase_06 AC 55 ms
50,684 KB
testcase_07 AC 55 ms
50,544 KB
testcase_08 AC 55 ms
50,644 KB
testcase_09 AC 57 ms
50,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.stream.Stream;

class Main {
    public static void main(String[] args) {
        no21();
    }

    // No.21 平均の差
    private static void no21(){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

               // 数字の個数
               int totalNumber;
               // グループ数
               String groups;
               // 数字
               String[] inputNumbers;
       
               try {
                   String tn = reader.readLine();
                   totalNumber = Integer.parseInt(tn);

                   groups = reader.readLine();

                   inputNumbers = new String[totalNumber];
                   
                   for(int i = 0; i < totalNumber; i++){
                        inputNumbers[i] = reader.readLine();
                   }
                   reader.close();
               } catch (IOException e) {
                   throw new UncheckedIOException(e);
               }

               int[] numbers = Stream.of(inputNumbers).mapToInt(Integer::parseInt).sorted().toArray();

               // 平均の差を求める
               System.out.println(numbers[totalNumber - 1] - numbers[0]);
    }
}
0