結果
問題 | No.275 中央値を求めよ |
ユーザー |
![]() |
提出日時 | 2015-11-08 21:42:00 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 186 ms / 1,000 ms |
コード長 | 641 bytes |
コンパイル時間 | 2,701 ms |
コンパイル使用メモリ | 87,112 KB |
実行使用メモリ | 42,104 KB |
最終ジャッジ日時 | 2024-06-24 23:29:57 |
合計ジャッジ時間 | 10,265 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
import java.util.*;public class Main {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int n = Integer.parseInt(scanner.next());ArrayList<Integer> list = new ArrayList<>();for (int i = 0; i < n; i++) {list.add(Integer.parseInt(scanner.next()));}Collections.sort(list);float answer;if (n % 2 == 0) {answer = ((list.get((int) (n / 2.f) - 1)) + (list.get((int) (n / 2.f)))) / 2.f;} else {answer = ((float) list.get((n / 2)));}System.out.println(answer);}}