結果

問題 No.275 中央値を求めよ
ユーザー AoiroFukurouAoiroFukurou
提出日時 2015-09-18 20:02:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 204 ms / 1,000 ms
コード長 637 bytes
コンパイル時間 6,345 ms
コンパイル使用メモリ 73,992 KB
実行使用メモリ 56,860 KB
最終ジャッジ日時 2023-09-07 04:46:10
合計ジャッジ時間 11,655 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,576 KB
testcase_01 AC 126 ms
55,796 KB
testcase_02 AC 141 ms
55,788 KB
testcase_03 AC 127 ms
55,700 KB
testcase_04 AC 123 ms
55,644 KB
testcase_05 AC 126 ms
55,640 KB
testcase_06 AC 137 ms
55,928 KB
testcase_07 AC 198 ms
56,500 KB
testcase_08 AC 144 ms
55,608 KB
testcase_09 AC 145 ms
55,792 KB
testcase_10 AC 146 ms
55,820 KB
testcase_11 AC 129 ms
55,888 KB
testcase_12 AC 128 ms
55,440 KB
testcase_13 AC 126 ms
55,984 KB
testcase_14 AC 128 ms
55,876 KB
testcase_15 AC 204 ms
56,632 KB
testcase_16 AC 198 ms
56,572 KB
testcase_17 AC 200 ms
56,488 KB
testcase_18 AC 159 ms
56,100 KB
testcase_19 AC 201 ms
56,136 KB
testcase_20 AC 200 ms
56,452 KB
testcase_21 AC 175 ms
55,600 KB
testcase_22 AC 200 ms
56,452 KB
testcase_23 AC 180 ms
56,136 KB
testcase_24 AC 154 ms
55,844 KB
testcase_25 AC 203 ms
56,764 KB
testcase_26 AC 197 ms
55,920 KB
testcase_27 AC 198 ms
56,428 KB
testcase_28 AC 137 ms
55,668 KB
testcase_29 AC 160 ms
56,248 KB
testcase_30 AC 137 ms
55,740 KB
testcase_31 AC 196 ms
56,408 KB
testcase_32 AC 143 ms
55,848 KB
testcase_33 AC 201 ms
56,424 KB
testcase_34 AC 137 ms
55,660 KB
testcase_35 AC 195 ms
56,800 KB
testcase_36 AC 161 ms
56,048 KB
testcase_37 AC 143 ms
55,584 KB
testcase_38 AC 152 ms
55,984 KB
testcase_39 AC 154 ms
56,108 KB
testcase_40 AC 201 ms
56,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yuki_coder;

import java.util.Scanner;

public class No_275 {
public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int[] a = new int[n];
	for(int i=0; i<a.length; i++){
		a[i] = sc.nextInt();
	}
	for(int i=0; i<a.length-1; i++){
		for(int j=a.length-1; j>i; j--){
			if(a[j] < a[j-1]){
				int t = a[j];
				a[j]=a[j-1];
				a[j-1]=t;
			}
		}
	}
	if(n%2==1){
		int b = (n+1)/2;
		System.out.println(a[b-1]);
	}else if(n%2==0){
		double b = ((n+1.0)/2.0);
		int c = (int)((b - 0.5)-1);
		int d = (int)((b + 0.5)-1);
		double e = (a[c] + a[d])/2.0;
		System.out.println(e);
}
	}
}
0