結果

問題 No.275 中央値を求めよ
ユーザー koko_ukoko_u
提出日時 2015-10-04 23:54:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 157 ms / 1,000 ms
コード長 1,118 bytes
コンパイル時間 3,158 ms
コンパイル使用メモリ 79,636 KB
実行使用メモリ 56,916 KB
最終ジャッジ日時 2023-09-07 04:49:54
合計ジャッジ時間 10,266 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,524 KB
testcase_01 AC 125 ms
55,876 KB
testcase_02 AC 125 ms
55,508 KB
testcase_03 AC 124 ms
55,632 KB
testcase_04 AC 130 ms
55,532 KB
testcase_05 AC 128 ms
55,776 KB
testcase_06 AC 128 ms
55,888 KB
testcase_07 AC 124 ms
54,776 KB
testcase_08 AC 125 ms
55,812 KB
testcase_09 AC 127 ms
55,800 KB
testcase_10 AC 132 ms
55,776 KB
testcase_11 AC 124 ms
55,596 KB
testcase_12 AC 126 ms
55,768 KB
testcase_13 AC 130 ms
55,708 KB
testcase_14 AC 124 ms
55,756 KB
testcase_15 AC 140 ms
55,500 KB
testcase_16 AC 157 ms
56,916 KB
testcase_17 AC 134 ms
56,180 KB
testcase_18 AC 129 ms
56,068 KB
testcase_19 AC 136 ms
55,744 KB
testcase_20 AC 130 ms
54,784 KB
testcase_21 AC 128 ms
55,552 KB
testcase_22 AC 133 ms
54,508 KB
testcase_23 AC 141 ms
56,028 KB
testcase_24 AC 132 ms
55,908 KB
testcase_25 AC 128 ms
54,772 KB
testcase_26 AC 133 ms
55,004 KB
testcase_27 AC 125 ms
54,904 KB
testcase_28 AC 125 ms
55,420 KB
testcase_29 AC 127 ms
55,840 KB
testcase_30 AC 122 ms
55,748 KB
testcase_31 AC 124 ms
55,144 KB
testcase_32 AC 126 ms
55,684 KB
testcase_33 AC 125 ms
54,788 KB
testcase_34 AC 123 ms
55,700 KB
testcase_35 AC 120 ms
54,588 KB
testcase_36 AC 125 ms
55,936 KB
testcase_37 AC 123 ms
53,988 KB
testcase_38 AC 122 ms
55,476 KB
testcase_39 AC 125 ms
56,384 KB
testcase_40 AC 137 ms
55,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package jp.co.kokou.sample.no275;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.stream.Stream;

public class Main {

    public static void main(String[] args) {
        try (InputStreamReader isr = new InputStreamReader(System.in);
             BufferedReader br = new BufferedReader(isr)) {

            br.readLine(); // 最初の値は捨てる
            String[] strNums = br.readLine().split("\\s+");
            int[] nums = Stream.of(strNums).mapToInt(Integer::parseInt).toArray();
            System.out.format("%.1f%n", Median.calc(nums));
        } catch (IOException ex) {

        }
    }

    public static class Median {

        public static double calc(int... numbers) {
            int[] nums = Arrays.copyOf(numbers, numbers.length);
            Arrays.sort(nums);
            if (nums.length % 2 == 0) {  // 偶数
                return (nums[nums.length / 2 - 1] + nums[nums.length / 2]) / 2.0;
            } else { // 奇数
                return nums[nums.length / 2];
            }
        }
    }
}
0