結果

問題 No.275 中央値を求めよ
ユーザー fkwnw3_1243
提出日時 2017-05-02 21:46:03
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 829 bytes
コンパイル時間 2,007 ms
コンパイル使用メモリ 75,400 KB
実行使用メモリ 37,376 KB
最終ジャッジ日時 2024-09-14 04:47:21
合計ジャッジ時間 5,525 ms
ジャッジサーバーID
(参考情報)
judge4 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 24 WA * 13 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

import static java.lang.System.in;


public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        int N = Integer.parseInt(reader.readLine());
        int[] table = new int[N];
        String[] inputs = reader.readLine().split(" ");
        for (int i = 0; i < N; i++) {
            table[i] = Integer.parseInt(inputs[i]);
        }
        Arrays.sort(table);
        if (N % 2 == 0) {
            int left = table[(N/2)-1];
            int right = table[(N/2)];
            System.out.println((left + right) / 2.0);
        } else {
            System.out.println(table[(N/2)+1]);
        }
    }
}
0