結果

問題 No.275 中央値を求めよ
ユーザー takutakutakutaku
提出日時 2020-09-17 09:43:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 190 ms / 1,000 ms
コード長 733 bytes
コンパイル時間 2,795 ms
コンパイル使用メモリ 72,856 KB
実行使用メモリ 57,932 KB
最終ジャッジ日時 2023-09-04 07:06:53
合計ジャッジ時間 9,830 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
56,452 KB
testcase_01 AC 121 ms
57,932 KB
testcase_02 AC 136 ms
55,728 KB
testcase_03 AC 123 ms
55,792 KB
testcase_04 AC 124 ms
55,564 KB
testcase_05 AC 130 ms
55,908 KB
testcase_06 AC 135 ms
55,684 KB
testcase_07 AC 180 ms
56,100 KB
testcase_08 AC 139 ms
55,724 KB
testcase_09 AC 142 ms
55,684 KB
testcase_10 AC 142 ms
55,504 KB
testcase_11 AC 125 ms
55,932 KB
testcase_12 AC 124 ms
56,408 KB
testcase_13 AC 126 ms
55,720 KB
testcase_14 AC 125 ms
56,056 KB
testcase_15 AC 189 ms
56,180 KB
testcase_16 AC 190 ms
57,272 KB
testcase_17 AC 189 ms
55,988 KB
testcase_18 AC 155 ms
56,352 KB
testcase_19 AC 188 ms
56,848 KB
testcase_20 AC 184 ms
56,080 KB
testcase_21 AC 183 ms
56,016 KB
testcase_22 AC 187 ms
56,644 KB
testcase_23 AC 170 ms
55,712 KB
testcase_24 AC 151 ms
56,100 KB
testcase_25 AC 185 ms
56,680 KB
testcase_26 AC 186 ms
56,696 KB
testcase_27 AC 172 ms
56,188 KB
testcase_28 AC 134 ms
55,604 KB
testcase_29 AC 162 ms
55,960 KB
testcase_30 AC 132 ms
55,880 KB
testcase_31 AC 185 ms
56,512 KB
testcase_32 AC 141 ms
56,416 KB
testcase_33 AC 186 ms
56,208 KB
testcase_34 AC 135 ms
55,496 KB
testcase_35 AC 174 ms
56,060 KB
testcase_36 AC 176 ms
56,040 KB
testcase_37 AC 142 ms
53,704 KB
testcase_38 AC 151 ms
55,912 KB
testcase_39 AC 158 ms
56,000 KB
testcase_40 AC 188 ms
57,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main(String[] args) {
	    
	    Scanner sc = new Scanner(System.in);
	    int n = sc.nextInt();
	    
	    // 整数Aを配列に格納する
	    int[] number = new int[n];
	    for(int i = 0; i < n; i++) {
	        number[i] = sc.nextInt();
	    }
	    
	    // 小さい順にソートする
	    Arrays.sort(number);
	    double result = 0;
	    
	    // 整数Aが偶数個の時
	    if(n % 2 == 0) {
	        int central = n / 2;
	        result = ((double)number[central - 1] + (double)number[central]) / 2;
	    }else {
	        int central = n / 2;
	        result = (double)number[central];   // +1を消去
	    }
	    
	    System.out.println(result);
	}
}

0