結果
| 問題 |
No.275 中央値を求めよ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-02-19 15:04:09 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 191 ms / 1,000 ms |
| コード長 | 766 bytes |
| コンパイル時間 | 3,522 ms |
| コンパイル使用メモリ | 76,612 KB |
| 実行使用メモリ | 42,864 KB |
| 最終ジャッジ日時 | 2024-06-25 00:18:41 |
| 合計ジャッジ時間 | 11,106 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
ソースコード
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class CenterNum {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
ArrayList<Integer> list = new ArrayList();
for(int i=0;i<n;i++){
list.add(scanner.nextInt());
}
Collections.sort(list);
if(list.size() % 2 == 0){
float num = (list.get(list.size()/2 - 1) + list.get(list.size()/2)) / 2.0f;
System.out.println(String.format("%.1f", num));
}else{
int num = list.get(list.size()/2);
System.out.println(num);
}
}
}