結果
問題 | No.275 中央値を求めよ |
ユーザー |
|
提出日時 | 2016-01-11 11:55:34 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 61 ms / 1,000 ms |
コード長 | 841 bytes |
コンパイル時間 | 3,845 ms |
コンパイル使用メモリ | 75,320 KB |
実行使用メモリ | 37,452 KB |
最終ジャッジ日時 | 2024-06-24 23:39:10 |
合計ジャッジ時間 | 6,433 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class No0275 { public static void main(String[] args) { try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) { int N = Integer.parseInt(br.readLine()); String[] str = br.readLine().split(" "); int[] A = new int[N]; int length = A.length; int l = length / 2; for (int i = 0; i < N ; i++) { A[i] = Integer.parseInt(str[i]); } Arrays.sort(A); if(length % 2 == 0){ System.out.println( (double)(A[l - 1] + A[l]) / 2); } else { System.out.println(A[l]); } } catch (IOException e) { e.printStackTrace(); } } }