結果

問題 No.275 中央値を求めよ
ユーザー kanotown
提出日時 2018-12-14 16:09:27
言語 Java
(openjdk 23)
結果
AC  
実行時間 190 ms / 1,000 ms
コード長 588 bytes
コンパイル時間 3,815 ms
コンパイル使用メモリ 75,156 KB
実行使用メモリ 54,720 KB
最終ジャッジ日時 2024-09-25 05:11:22
合計ジャッジ時間 11,482 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;
public class No275 {
    public static void main(String[] args) {
        // 標準入力
        Scanner sc = new Scanner(System.in);
            
        int n = sc.nextInt();
        int[] a = new int[n];
        float result;
        
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        
        if (n % 2 == 0) {
            result = (a[n / 2] + a[n / 2 - 1]) / 2.0f;
        } else {
            result = a[n / 2];
        }
        System.out.println(result);
    }
}
0