結果
問題 | No.275 中央値を求めよ |
ユーザー |
|
提出日時 | 2015-10-04 23:54:25 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 152 ms / 1,000 ms |
コード長 | 1,118 bytes |
コンパイル時間 | 2,308 ms |
コンパイル使用メモリ | 89,992 KB |
実行使用メモリ | 42,012 KB |
最終ジャッジ日時 | 2024-06-24 23:21:59 |
合計ジャッジ時間 | 8,701 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
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]; } } } }