結果
問題 | No.275 中央値を求めよ |
ユーザー |
![]() |
提出日時 | 2020-04-09 19:00:48 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 203 ms / 1,000 ms |
コード長 | 809 bytes |
コンパイル時間 | 4,858 ms |
コンパイル使用メモリ | 83,028 KB |
実行使用メモリ | 55,136 KB |
最終ジャッジ日時 | 2024-09-13 20:17:51 |
合計ジャッジ時間 | 12,169 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
import java.lang.reflect.Array;import java.math.BigDecimal;import java.math.RoundingMode;import java.util.ArrayList;import java.util.Collections;import java.util.List;import java.util.Scanner;public class No275 {public static void main(String[] args) {// 標準入力から読み込む際に、Scannerオブジェクトを使う。Scanner sc = new Scanner(System.in);int n = sc.nextInt();List<Integer> intList = new ArrayList<>();while (sc.hasNext()) {intList.add(sc.nextInt());}Collections.sort(intList);if (n%2 == 1) {System.out.println(intList.get(n/2));} else {double ans = intList.get(n/2-1) + intList.get(n/2);System.out.println(ans/2);}}}