結果

問題 No.275 中央値を求めよ
ユーザー YukimotoPG
提出日時 2019-02-14 08:41:02
言語 Java
(openjdk 23)
結果
AC  
実行時間 193 ms / 1,000 ms
コード長 386 bytes
コンパイル時間 2,087 ms
コンパイル使用メモリ 75,072 KB
実行使用メモリ 43,032 KB
最終ジャッジ日時 2024-09-13 11:17:05
合計ジャッジ時間 10,273 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		int n = sc.nextInt();
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = sc.nextInt();
		Arrays.sort(ar);
		if (n%2 == 0) {
			//012345
			System.out.println((double)(ar[(n-1)/2]+ar[n/2])/2);
		}
		else {
			System.out.println(ar[(n-1)/2]);
		}
		
	}
}
0