結果

問題 No.275 中央値を求めよ
ユーザー yonaka_ggg
提出日時 2020-09-06 15:43:28
言語 Java
(openjdk 23)
結果
AC  
実行時間 186 ms / 1,000 ms
コード長 557 bytes
コンパイル時間 2,675 ms
コンパイル使用メモリ 74,228 KB
実行使用メモリ 42,476 KB
最終ジャッジ日時 2024-11-29 07:13:49
合計ジャッジ時間 9,894 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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[] a = new int[n];
        for(int i = 0; i < n; i++)
        	a[i] = sc.nextInt();
        
        Arrays.sort(a);
        double ans = 0;
        if(n % 2 == 0) {
        	ans = Math.round(((a[n / 2 - 1] + a[n / 2]) * 10) / 2);
        	ans /= 10;
        }
        else ans = Math.round(a[n / 2]);
        
        System.out.println(ans);
    }

}
0