結果

問題 No.275 中央値を求めよ
ユーザー Hiroaki Kono
提出日時 2017-10-26 21:35:10
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 658 bytes
コンパイル時間 3,293 ms
コンパイル使用メモリ 76,724 KB
実行使用メモリ 42,692 KB
最終ジャッジ日時 2024-11-21 20:10:36
合計ジャッジ時間 10,923 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 13 WA * 24 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Scanner;

public class No275 {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int count = s.nextInt();
        int[] arr = new int[count];
        for (int i = 0; i < count; i++) {
            arr[i] = s.nextInt();
        }
        Arrays.sort(arr);

        double median;
        if (count % 2 == 0) {
            median = (double) ((arr[count / 2] + arr[count / 2 - 1]) / 2);
        } else {
            median = (double) arr[count / 2 - 1];
        }
        System.out.println(new DecimalFormat(".#").format(median));
    }
}
0