結果
| 問題 |
No.275 中央値を求めよ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-07-19 16:01:18 |
| 言語 | Java (openjdk 23) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 612 bytes |
| コンパイル時間 | 2,172 ms |
| コンパイル使用メモリ | 74,292 KB |
| 実行使用メモリ | 42,780 KB |
| 最終ジャッジ日時 | 2024-07-01 19:04:52 |
| 合計ジャッジ時間 | 10,048 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 2 |
| other | AC * 21 WA * 14 RE * 3 |
ソースコード
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int[] arr = new int[num];
for(int i=0;i<num;i++){
arr[i] = sc.nextInt();
}
// ソート
Arrays.sort(arr);
int cnt = num / 2;
double center = 0;
// 中央値算出
if(num % 2 == 0){
// 偶数
center = (arr[cnt] + arr[cnt + 1]) / 2;
}else {
// 奇数
center = arr[cnt];
}
System.out.println(center);
}
}