結果

問題 No.275 中央値を求めよ
ユーザー 4A9GN
提出日時 2016-07-20 22:01:45
言語 Java
(openjdk 23)
結果
AC  
実行時間 198 ms / 1,000 ms
コード長 765 bytes
コンパイル時間 2,134 ms
コンパイル使用メモリ 74,700 KB
実行使用メモリ 54,948 KB
最終ジャッジ日時 2024-06-24 23:55:23
合計ジャッジ時間 9,589 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int size = sc.nextInt();
        int[] num = new int[size];
        int i, j, temp, m;

        for (i = 0; i < size; i++) //read
            num[i] = sc.nextInt();
        //sort desc
        for (i = 1; i < size; i++) {
            temp = num[i];
            for (j = i-1; j >= 0 && temp < num[j]; j--)
                num[j+1] = num[j];
            num[j+1] = temp;
        }
        m = (int)(size/2+0.99999); //chuo
        if (size % 2 == 0) {
            i = m-1;
            System.out.printf("%.1f\n", (double)(num[m]+num[i])/2);
            return;
        }
        System.out.printf("%d\n", num[m]);
    }
}
0