結果

問題 No.275 中央値を求めよ
ユーザー eagleeagle
提出日時 2022-05-26 15:10:24
言語 Java19
(openjdk 21)
結果
AC  
実行時間 210 ms / 1,000 ms
コード長 659 bytes
コンパイル時間 2,056 ms
コンパイル使用メモリ 77,376 KB
実行使用メモリ 58,492 KB
最終ジャッジ日時 2023-10-20 19:27:34
合計ジャッジ時間 10,204 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
57,432 KB
testcase_01 AC 129 ms
57,332 KB
testcase_02 AC 143 ms
57,148 KB
testcase_03 AC 130 ms
57,484 KB
testcase_04 AC 129 ms
57,368 KB
testcase_05 AC 130 ms
57,548 KB
testcase_06 AC 139 ms
57,504 KB
testcase_07 AC 193 ms
57,732 KB
testcase_08 AC 146 ms
57,552 KB
testcase_09 AC 146 ms
57,560 KB
testcase_10 AC 147 ms
57,588 KB
testcase_11 AC 131 ms
57,472 KB
testcase_12 AC 131 ms
57,456 KB
testcase_13 AC 132 ms
57,556 KB
testcase_14 AC 131 ms
57,544 KB
testcase_15 AC 209 ms
57,716 KB
testcase_16 AC 205 ms
57,980 KB
testcase_17 AC 206 ms
57,564 KB
testcase_18 AC 162 ms
57,580 KB
testcase_19 AC 194 ms
57,624 KB
testcase_20 AC 200 ms
57,688 KB
testcase_21 AC 188 ms
57,632 KB
testcase_22 AC 204 ms
57,736 KB
testcase_23 AC 190 ms
57,608 KB
testcase_24 AC 156 ms
57,612 KB
testcase_25 AC 203 ms
57,480 KB
testcase_26 AC 210 ms
57,560 KB
testcase_27 AC 198 ms
57,640 KB
testcase_28 AC 141 ms
57,400 KB
testcase_29 AC 184 ms
57,568 KB
testcase_30 AC 141 ms
57,572 KB
testcase_31 AC 198 ms
57,536 KB
testcase_32 AC 148 ms
57,608 KB
testcase_33 AC 202 ms
57,620 KB
testcase_34 AC 142 ms
57,600 KB
testcase_35 AC 202 ms
58,492 KB
testcase_36 AC 190 ms
57,624 KB
testcase_37 AC 146 ms
57,564 KB
testcase_38 AC 157 ms
57,532 KB
testcase_39 AC 156 ms
57,300 KB
testcase_40 AC 201 ms
57,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		//小さい順に並び替える
		for(int i = 0 ; i < N - 1; i++) {
			for(int j = i + 1; j < N; j++) {
				if(A[i] > A[j]) {
					int num = A[i];
					A[i] = A[j];
					A[j] = num;
				}
			}
		}
		double ans;
		//中央値を求める
		if(N % 2 == 0) {
			ans = (A[N / 2] + A[N / 2 - 1]) / 2.0;
		} else {
			ans = A[N / 2];
		}
		System.out.println(ans);
	}
}
0