結果

問題 No.275 中央値を求めよ
ユーザー hippolover02hippolover02
提出日時 2022-07-19 16:21:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 195 ms / 1,000 ms
コード長 624 bytes
コンパイル時間 2,104 ms
コンパイル使用メモリ 71,780 KB
実行使用メモリ 58,344 KB
最終ジャッジ日時 2023-09-14 12:04:01
合計ジャッジ時間 10,248 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,904 KB
testcase_01 AC 126 ms
58,344 KB
testcase_02 AC 140 ms
55,992 KB
testcase_03 AC 127 ms
55,888 KB
testcase_04 AC 127 ms
56,016 KB
testcase_05 AC 125 ms
56,016 KB
testcase_06 AC 138 ms
55,836 KB
testcase_07 AC 183 ms
55,704 KB
testcase_08 AC 144 ms
56,032 KB
testcase_09 AC 143 ms
53,708 KB
testcase_10 AC 144 ms
54,016 KB
testcase_11 AC 127 ms
55,624 KB
testcase_12 AC 129 ms
55,584 KB
testcase_13 AC 127 ms
55,880 KB
testcase_14 AC 127 ms
55,900 KB
testcase_15 AC 191 ms
56,636 KB
testcase_16 AC 193 ms
56,276 KB
testcase_17 AC 195 ms
56,132 KB
testcase_18 AC 160 ms
55,948 KB
testcase_19 AC 185 ms
55,900 KB
testcase_20 AC 180 ms
57,016 KB
testcase_21 AC 176 ms
55,848 KB
testcase_22 AC 190 ms
56,416 KB
testcase_23 AC 185 ms
56,596 KB
testcase_24 AC 152 ms
56,244 KB
testcase_25 AC 193 ms
55,856 KB
testcase_26 AC 187 ms
56,064 KB
testcase_27 AC 186 ms
56,028 KB
testcase_28 AC 138 ms
56,104 KB
testcase_29 AC 159 ms
55,844 KB
testcase_30 AC 137 ms
55,984 KB
testcase_31 AC 187 ms
56,236 KB
testcase_32 AC 146 ms
55,748 KB
testcase_33 AC 189 ms
56,248 KB
testcase_34 AC 138 ms
56,016 KB
testcase_35 AC 173 ms
54,332 KB
testcase_36 AC 180 ms
56,652 KB
testcase_37 AC 144 ms
55,936 KB
testcase_38 AC 153 ms
55,820 KB
testcase_39 AC 152 ms
55,944 KB
testcase_40 AC 190 ms
56,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int[] arr = new int[num];
        for(int i=0;i<num;i++){
            arr[i] = sc.nextInt();
        }
        // ソート
        Arrays.sort(arr);
        int cnt = num / 2;
        double center;
        // 中央値算出
        if(num % 2 == 0){
            // 偶数
            center = ((double)arr[cnt] + (double)arr[cnt - 1]) / 2;
        }else {
            // 奇数
            center = arr[cnt];
        }
        System.out.println(center);
	}
}
0