結果

問題 No.275 中央値を求めよ
ユーザー Matumo
提出日時 2018-07-13 03:35:00
言語 Java
(openjdk 23)
結果
AC  
実行時間 192 ms / 1,000 ms
コード長 525 bytes
コンパイル時間 2,117 ms
コンパイル使用メモリ 75,304 KB
実行使用メモリ 55,964 KB
最終ジャッジ日時 2024-06-25 01:53:27
合計ジャッジ時間 9,725 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int n = sc.nextInt();
		int[] as = new int[n];

		for(int i = 0; i < n; i++) {
			as[i] = sc.nextInt();
		}

		Arrays.sort(as);
		if(n % 2 != 0) {
			System.out.println(as[n / 2]);
		} else {
			double a = (as[(n / 2) - 1] + as[n / 2]) / 2.0;
			BigDecimal bd = new BigDecimal(a).setScale(1);
			System.out.println(bd);
		}
    }
}
0