結果

問題 No.275 中央値を求めよ
ユーザー tenten
提出日時 2020-11-11 09:04:35
言語 Java
(openjdk 23)
結果
AC  
実行時間 164 ms / 1,000 ms
コード長 500 bytes
コンパイル時間 2,364 ms
コンパイル使用メモリ 74,336 KB
実行使用メモリ 43,060 KB
最終ジャッジ日時 2024-07-22 18:19:55
合計ジャッジ時間 8,772 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);
        double ans;
        if (n % 2 == 0) {
            ans = (arr[n / 2 - 1] + arr[n / 2]) / 2.0;
        } else {
            ans = arr[n / 2];
        }
        System.out.println(ans);
    }
}
0