結果

問題 No.275 中央値を求めよ
ユーザー hippolover02hippolover02
提出日時 2022-07-19 16:01:18
言語 Java19
(openjdk 21)
結果
RE  
実行時間 -
コード長 612 bytes
コンパイル時間 3,619 ms
コンパイル使用メモリ 72,360 KB
実行使用メモリ 58,064 KB
最終ジャッジ日時 2023-09-14 11:37:15
合計ジャッジ時間 12,007 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 WA -
testcase_03 AC 124 ms
55,876 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 139 ms
55,728 KB
testcase_09 AC 140 ms
56,144 KB
testcase_10 WA -
testcase_11 AC 125 ms
55,896 KB
testcase_12 RE -
testcase_13 AC 125 ms
55,692 KB
testcase_14 AC 122 ms
55,804 KB
testcase_15 WA -
testcase_16 AC 184 ms
56,276 KB
testcase_17 AC 183 ms
55,984 KB
testcase_18 WA -
testcase_19 AC 179 ms
53,916 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 169 ms
56,140 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 184 ms
56,164 KB
testcase_27 AC 187 ms
56,280 KB
testcase_28 AC 136 ms
55,660 KB
testcase_29 AC 169 ms
56,148 KB
testcase_30 AC 132 ms
56,076 KB
testcase_31 WA -
testcase_32 AC 141 ms
55,720 KB
testcase_33 AC 185 ms
56,100 KB
testcase_34 AC 136 ms
55,672 KB
testcase_35 AC 183 ms
56,140 KB
testcase_36 AC 178 ms
56,312 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 151 ms
55,676 KB
testcase_40 AC 187 ms
56,020 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 = 0;
        // 中央値算出
        if(num % 2 == 0){
            // 偶数
            center = (arr[cnt] + arr[cnt + 1]) / 2;
        }else {
            // 奇数
            center = arr[cnt];
        }
        System.out.println(center);
	}
}
0