結果

問題 No.275 中央値を求めよ
ユーザー hippolover02hippolover02
提出日時 2022-07-19 16:13:15
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 608 bytes
コンパイル時間 1,933 ms
コンパイル使用メモリ 71,584 KB
実行使用メモリ 58,140 KB
最終ジャッジ日時 2023-09-14 11:54:28
合計ジャッジ時間 10,400 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 123 ms
56,340 KB
testcase_04 AC 124 ms
55,628 KB
testcase_05 WA -
testcase_06 AC 133 ms
58,140 KB
testcase_07 AC 179 ms
56,392 KB
testcase_08 AC 140 ms
55,804 KB
testcase_09 AC 140 ms
55,728 KB
testcase_10 WA -
testcase_11 AC 123 ms
55,876 KB
testcase_12 AC 124 ms
56,116 KB
testcase_13 AC 124 ms
56,072 KB
testcase_14 AC 123 ms
56,092 KB
testcase_15 WA -
testcase_16 AC 189 ms
56,228 KB
testcase_17 AC 186 ms
56,232 KB
testcase_18 WA -
testcase_19 AC 172 ms
56,164 KB
testcase_20 AC 182 ms
56,408 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 160 ms
56,272 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 188 ms
56,140 KB
testcase_27 AC 184 ms
56,144 KB
testcase_28 AC 136 ms
56,072 KB
testcase_29 AC 157 ms
55,992 KB
testcase_30 AC 136 ms
55,960 KB
testcase_31 AC 187 ms
56,496 KB
testcase_32 AC 140 ms
56,176 KB
testcase_33 AC 181 ms
56,248 KB
testcase_34 AC 135 ms
55,932 KB
testcase_35 AC 183 ms
56,540 KB
testcase_36 AC 163 ms
56,032 KB
testcase_37 AC 142 ms
55,764 KB
testcase_38 AC 157 ms
55,880 KB
testcase_39 AC 150 ms
55,836 KB
testcase_40 AC 186 ms
55,912 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 = (arr[cnt] + arr[cnt - 1]) / 2;
        }else {
            // 奇数
            center = arr[cnt];
        }
        System.out.println(center);
	}
}
0