結果

問題 No.275 中央値を求めよ
ユーザー mits58
提出日時 2016-05-05 14:25:10
言語 Java
(openjdk 23)
結果
AC  
実行時間 186 ms / 1,000 ms
コード長 507 bytes
コンパイル時間 2,448 ms
コンパイル使用メモリ 75,436 KB
実行使用メモリ 42,856 KB
最終ジャッジ日時 2024-06-24 23:48:58
合計ジャッジ時間 9,650 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(sc.hasNext()){
        	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 res=((double)a[n/2]+(double)a[n/2-1])/2;
        		System.out.println(res);
        	}
        }
    }
}
0