結果

問題 No.275 中央値を求めよ
ユーザー Tsukasa_Type
提出日時 2018-02-08 22:38:49
言語 Java
(openjdk 23)
結果
AC  
実行時間 186 ms / 1,000 ms
コード長 471 bytes
コンパイル時間 2,107 ms
コンパイル使用メモリ 74,788 KB
実行使用メモリ 43,008 KB
最終ジャッジ日時 2024-06-25 00:50:29
合計ジャッジ時間 9,478 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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