結果

問題 No.275 中央値を求めよ
ユーザー TwinkleStar74TwinkleStar74
提出日時 2017-09-13 01:24:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 195 ms / 1,000 ms
コード長 677 bytes
コンパイル時間 2,631 ms
コンパイル使用メモリ 71,544 KB
実行使用メモリ 57,820 KB
最終ジャッジ日時 2023-09-07 06:15:03
合計ジャッジ時間 10,350 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,644 KB
testcase_01 AC 128 ms
55,616 KB
testcase_02 AC 140 ms
55,576 KB
testcase_03 AC 127 ms
55,624 KB
testcase_04 AC 126 ms
55,548 KB
testcase_05 AC 127 ms
55,628 KB
testcase_06 AC 137 ms
55,368 KB
testcase_07 AC 185 ms
55,580 KB
testcase_08 AC 143 ms
55,628 KB
testcase_09 AC 144 ms
55,428 KB
testcase_10 AC 144 ms
55,700 KB
testcase_11 AC 128 ms
55,516 KB
testcase_12 AC 127 ms
55,520 KB
testcase_13 AC 129 ms
55,356 KB
testcase_14 AC 129 ms
55,568 KB
testcase_15 AC 193 ms
56,136 KB
testcase_16 AC 195 ms
55,944 KB
testcase_17 AC 191 ms
55,912 KB
testcase_18 AC 161 ms
55,844 KB
testcase_19 AC 187 ms
56,220 KB
testcase_20 AC 185 ms
55,560 KB
testcase_21 AC 159 ms
56,340 KB
testcase_22 AC 192 ms
55,972 KB
testcase_23 AC 160 ms
55,724 KB
testcase_24 AC 157 ms
57,820 KB
testcase_25 AC 192 ms
55,828 KB
testcase_26 AC 191 ms
55,816 KB
testcase_27 AC 190 ms
55,952 KB
testcase_28 AC 139 ms
55,596 KB
testcase_29 AC 159 ms
55,800 KB
testcase_30 AC 138 ms
55,596 KB
testcase_31 AC 187 ms
56,032 KB
testcase_32 AC 145 ms
55,480 KB
testcase_33 AC 188 ms
56,504 KB
testcase_34 AC 138 ms
55,368 KB
testcase_35 AC 189 ms
55,920 KB
testcase_36 AC 184 ms
55,864 KB
testcase_37 AC 147 ms
55,560 KB
testcase_38 AC 156 ms
55,528 KB
testcase_39 AC 158 ms
55,772 KB
testcase_40 AC 190 ms
55,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;
class No275 {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        double x[] = new double[n];  //n個の整数を入れるdouble型の配列xを作成
        
		for(int i=0; i<n; i++){  //入力した数字を一つずつxに入れていく
			x[i]=sc.nextInt();
		}
		Arrays.sort(x);  //数字を昇順にソートする
		
		/*nが奇数なら真ん中の数字、偶数なら真ん中に近い二つの数値の和/2を取る*/
		if(n%2!=0){
			System.out.print(x[n/2]);
		}
		else {
			System.out.print( (x[(n/2)-1] + x[n/2])/2);
		}
		
		sc.close();
	}

}
0