結果

問題 No.275 中央値を求めよ
ユーザー S1hoS1ho
提出日時 2017-02-19 15:04:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 202 ms / 1,000 ms
コード長 766 bytes
コンパイル時間 3,436 ms
コンパイル使用メモリ 74,660 KB
実行使用メモリ 56,856 KB
最終ジャッジ日時 2023-09-07 05:51:57
合計ジャッジ時間 11,830 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,580 KB
testcase_01 AC 127 ms
55,848 KB
testcase_02 AC 144 ms
56,284 KB
testcase_03 AC 127 ms
55,972 KB
testcase_04 AC 131 ms
56,056 KB
testcase_05 AC 127 ms
55,632 KB
testcase_06 AC 140 ms
56,092 KB
testcase_07 AC 191 ms
56,308 KB
testcase_08 AC 145 ms
55,640 KB
testcase_09 AC 145 ms
55,856 KB
testcase_10 AC 149 ms
55,860 KB
testcase_11 AC 127 ms
53,668 KB
testcase_12 AC 130 ms
55,800 KB
testcase_13 AC 124 ms
55,508 KB
testcase_14 AC 127 ms
55,944 KB
testcase_15 AC 202 ms
56,368 KB
testcase_16 AC 194 ms
56,164 KB
testcase_17 AC 196 ms
56,400 KB
testcase_18 AC 158 ms
55,528 KB
testcase_19 AC 183 ms
56,452 KB
testcase_20 AC 198 ms
56,672 KB
testcase_21 AC 171 ms
56,224 KB
testcase_22 AC 194 ms
56,216 KB
testcase_23 AC 176 ms
56,060 KB
testcase_24 AC 155 ms
56,104 KB
testcase_25 AC 201 ms
56,856 KB
testcase_26 AC 187 ms
55,720 KB
testcase_27 AC 184 ms
56,668 KB
testcase_28 AC 135 ms
55,972 KB
testcase_29 AC 179 ms
56,056 KB
testcase_30 AC 139 ms
55,480 KB
testcase_31 AC 197 ms
56,824 KB
testcase_32 AC 144 ms
55,844 KB
testcase_33 AC 192 ms
56,240 KB
testcase_34 AC 140 ms
55,852 KB
testcase_35 AC 191 ms
56,040 KB
testcase_36 AC 180 ms
54,412 KB
testcase_37 AC 149 ms
55,768 KB
testcase_38 AC 156 ms
56,204 KB
testcase_39 AC 154 ms
55,720 KB
testcase_40 AC 192 ms
56,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class CenterNum {

    public static void main(String[] args) {
        
        Scanner scanner = new Scanner(System.in);
        
        int n = scanner.nextInt();
        
        ArrayList<Integer> list = new ArrayList();
        
        for(int i=0;i<n;i++){
            list.add(scanner.nextInt());
        }
        
        Collections.sort(list);
        
   
        if(list.size() % 2 == 0){
            float num = (list.get(list.size()/2 - 1) + list.get(list.size()/2)) / 2.0f;
            System.out.println(String.format("%.1f", num));
        }else{
            int num = list.get(list.size()/2);
            System.out.println(num);
        }
    }
    
}
0