結果

問題 No.275 中央値を求めよ
ユーザー spacenaut
提出日時 2016-05-15 10:18:01
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 469 bytes
コンパイル時間 2,150 ms
コンパイル使用メモリ 76,992 KB
実行使用メモリ 54,892 KB
最終ジャッジ日時 2024-10-06 03:11:48
合計ジャッジ時間 9,382 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 28 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class No0275{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> array = new ArrayList<Integer>();
		
		int n = sc.nextInt();
		
		for(int i = 0; i < n; i++){
			array.add(sc.nextInt());
		}
		
		Collections.sort(array);
		
		double mid;
		if(n % 2 == 1){
			System.out.println(array.get(n / 2));
		}else{
			mid = (array.get(n / 2) + array.get(n / 2 - 1)) / 2;
			System.out.println(mid);
		}
	}
}
0