結果

問題 No.275 中央値を求めよ
ユーザー takutakutakutaku
提出日時 2020-09-17 09:40:49
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 720 bytes
コンパイル時間 2,019 ms
コンパイル使用メモリ 74,504 KB
実行使用メモリ 56,092 KB
最終ジャッジ日時 2024-06-22 06:25:55
合計ジャッジ時間 9,115 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 24 WA * 13 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main(String[] args) {
	    
	    Scanner sc = new Scanner(System.in);
	    int n = sc.nextInt();
	    
	    // 整数Aを配列に格納する
	    int[] number = new int[n];
	    for(int i = 0; i < n; i++) {
	        number[i] = sc.nextInt();
	    }
	    
	    // 小さい順にソートする
	    Arrays.sort(number);
	    double result = 0;
	    
	    // 整数Aが偶数個の時
	    if(n % 2 == 0) {
	        int central = n / 2;
	        result = ((double)number[central - 1] + (double)number[central]) / 2;
	    }else {
	        int central = n / 2;
	        result = (double)number[central + 1];
	    }
	    
	    System.out.println(result);
	}
}

0