結果
| 問題 |
No.275 中央値を求めよ
|
| コンテスト | |
| ユーザー |
koukonko
|
| 提出日時 | 2015-12-23 16:10:47 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 101 ms / 1,000 ms |
| コード長 | 833 bytes |
| コンパイル時間 | 2,417 ms |
| コンパイル使用メモリ | 75,916 KB |
| 実行使用メモリ | 38,192 KB |
| 最終ジャッジ日時 | 2024-06-24 23:35:57 |
| 合計ジャッジ時間 | 5,347 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
ソースコード
package yukicoder;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) {
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
try {
int N = Integer.parseInt(buff.readLine());
int[] num = new int[N];
String[] box = buff.readLine().split(" ");
for (int i = 0; i < N; ++i) {
num[i] = Integer.parseInt(box[i]);
}
for (int i = 0; i < N / 2 + 1; ++i) {
for (int j = i + 1; j < N; ++j) {
if (num[i] > num[j]) {
int sw = num[i];
num[i] = num[j];
num[j] = sw;
}
}
}
double ans = 0;
if (N % 2 == 0) {
ans = (num[N / 2 - 1] + num[N / 2]) / 2d;
} else {
ans = num[N / 2];
}
System.out.println(ans);
} catch (Exception e) {
e.getStackTrace();
}
}
}
koukonko