結果

問題 No.275 中央値を求めよ
ユーザー hippolover02hippolover02
提出日時 2022-07-19 16:21:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 196 ms / 1,000 ms
コード長 624 bytes
コンパイル時間 4,903 ms
コンパイル使用メモリ 72,468 KB
実行使用メモリ 56,812 KB
最終ジャッジ日時 2023-09-14 12:03:48
合計ジャッジ時間 11,269 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
56,352 KB
testcase_01 AC 125 ms
55,868 KB
testcase_02 AC 141 ms
55,804 KB
testcase_03 AC 129 ms
55,820 KB
testcase_04 AC 128 ms
55,808 KB
testcase_05 AC 127 ms
55,868 KB
testcase_06 AC 137 ms
55,996 KB
testcase_07 AC 185 ms
55,936 KB
testcase_08 AC 147 ms
55,756 KB
testcase_09 AC 146 ms
55,852 KB
testcase_10 AC 145 ms
55,724 KB
testcase_11 AC 129 ms
56,172 KB
testcase_12 AC 130 ms
55,832 KB
testcase_13 AC 129 ms
55,852 KB
testcase_14 AC 127 ms
56,180 KB
testcase_15 AC 196 ms
56,048 KB
testcase_16 AC 194 ms
54,456 KB
testcase_17 AC 192 ms
56,516 KB
testcase_18 AC 160 ms
55,988 KB
testcase_19 AC 189 ms
56,100 KB
testcase_20 AC 183 ms
56,812 KB
testcase_21 AC 162 ms
54,044 KB
testcase_22 AC 192 ms
54,988 KB
testcase_23 AC 188 ms
56,012 KB
testcase_24 AC 156 ms
55,876 KB
testcase_25 AC 194 ms
56,020 KB
testcase_26 AC 189 ms
55,756 KB
testcase_27 AC 191 ms
56,272 KB
testcase_28 AC 137 ms
55,880 KB
testcase_29 AC 158 ms
56,044 KB
testcase_30 AC 138 ms
55,968 KB
testcase_31 AC 191 ms
56,036 KB
testcase_32 AC 144 ms
55,996 KB
testcase_33 AC 189 ms
56,644 KB
testcase_34 AC 139 ms
55,696 KB
testcase_35 AC 182 ms
56,312 KB
testcase_36 AC 174 ms
56,180 KB
testcase_37 AC 144 ms
56,124 KB
testcase_38 AC 154 ms
56,124 KB
testcase_39 AC 157 ms
55,816 KB
testcase_40 AC 193 ms
56,284 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