結果

問題 No.275 中央値を求めよ
ユーザー kohaku_kohaku
提出日時 2016-11-09 22:49:49
言語 Java
(openjdk 23)
結果
AC  
実行時間 185 ms / 1,000 ms
コード長 483 bytes
コンパイル時間 2,792 ms
コンパイル使用メモリ 77,136 KB
実行使用メモリ 42,956 KB
最終ジャッジ日時 2024-06-25 00:08:57
合計ジャッジ時間 9,307 ms
ジャッジサーバーID
(参考情報)
judge2 / 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 [] A = new int [N];
        for(int i=0; i<N; i++){
            A[i] = sc.nextInt();
        }
        Arrays.sort(A);
        
        if(N%2==1){
            System.out.println(A[(N-1)/2]);
        }else{
            double r = ( A[N/2-1] + A[N/2] )/2.0 ;
            System.out.println(r);
        }
    }
}
0