結果

問題 No.275 中央値を求めよ
ユーザー トミー
提出日時 2024-04-01 15:13:06
言語 Java
(openjdk 23)
結果
AC  
実行時間 201 ms / 1,000 ms
コード長 519 bytes
コンパイル時間 3,207 ms
コンパイル使用メモリ 74,220 KB
実行使用メモリ 54,596 KB
最終ジャッジ日時 2024-09-30 21:49:48
合計ジャッジ時間 10,781 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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[] a = new int[n];
        for (int i = 0; i != n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        if (n % 2 == 0) {
            System.out.println((double)(a[n / 2 - 1] + a[n / 2]) / 2);
            
        } else {
            System.out.println(a[n / 2]);
            
        }

        sc.close();

    }
}
0