結果

問題 No.275 中央値を求めよ
ユーザー GrenacheGrenache
提出日時 2015-09-04 22:24:25
言語 Java
(openjdk 23)
結果
AC  
実行時間 200 ms / 1,000 ms
コード長 574 bytes
コンパイル時間 3,851 ms
コンパイル使用メモリ 75,548 KB
実行使用メモリ 43,720 KB
最終ジャッジ日時 2024-06-24 23:07:40
合計ジャッジ時間 11,771 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;


public class Main_yukicoder275 {

    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);

        double ret;
        if (n % 2 != 0) {
        	ret = a[n / 2];
        } else {
        	ret = ((double)a[n / 2] + a[n / 2 - 1]) / 2;
        }
        
        System.out.printf("%.2f\n", ret);

        sc.close();
    }
}
0