結果
問題 | No.275 中央値を求めよ |
ユーザー |
|
提出日時 | 2023-02-01 20:58:13 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 205 ms / 1,000 ms |
コード長 | 531 bytes |
コンパイル時間 | 2,317 ms |
コンパイル使用メモリ | 75,968 KB |
実行使用メモリ | 42,772 KB |
最終ジャッジ日時 | 2024-07-01 14:19:03 |
合計ジャッジ時間 | 10,624 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
import java.util.Scanner; import java.util.ArrayList; import java.util.Collections; import java.util.List; class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); List<Integer> list = new ArrayList<Integer>(); for(int i = 0 ; i < num ; i++)list.add(sc.nextInt()); Collections.sort(list); if(num % 2 == 0) { System.out.println((float)(list.get(num / 2 ) + (list.get(num / 2 - 1) )) / 2); }else { System.out.println(list.get(num / 2 )); } } }