結果

問題 No.275 中央値を求めよ
ユーザー goma
提出日時 2017-09-19 22:09:26
言語 Java
(openjdk 23)
結果
AC  
実行時間 187 ms / 1,000 ms
コード長 442 bytes
コンパイル時間 1,932 ms
コンパイル使用メモリ 74,412 KB
実行使用メモリ 42,688 KB
最終ジャッジ日時 2024-06-25 00:40:11
合計ジャッジ時間 9,427 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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);
		int n = sc.nextInt();
		int ans[] = new int[n];

		for (int i = 0; i < n; i++) {
			ans[i] = sc.nextInt();
		}
		Arrays.sort(ans);
		if (n % 2 == 0) { // 奇数
			System.out.println((ans[(n / 2) - 1] + ans[n / 2]) / 2.0);
		} else { // 偶数
			System.out.println(ans[n / 2]);
		}
	}
}
0