結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,616 KB
testcase_01 AC 127 ms
55,396 KB
testcase_02 AC 142 ms
55,560 KB
testcase_03 AC 126 ms
55,432 KB
testcase_04 AC 127 ms
55,604 KB
testcase_05 AC 124 ms
55,632 KB
testcase_06 AC 136 ms
55,688 KB
testcase_07 AC 180 ms
56,104 KB
testcase_08 AC 142 ms
55,380 KB
testcase_09 AC 142 ms
55,676 KB
testcase_10 AC 142 ms
55,576 KB
testcase_11 AC 126 ms
55,476 KB
testcase_12 AC 125 ms
55,976 KB
testcase_13 AC 125 ms
55,464 KB
testcase_14 AC 125 ms
55,368 KB
testcase_15 AC 188 ms
56,384 KB
testcase_16 AC 192 ms
56,016 KB
testcase_17 AC 191 ms
55,952 KB
testcase_18 AC 155 ms
55,916 KB
testcase_19 AC 183 ms
56,064 KB
testcase_20 AC 190 ms
56,424 KB
testcase_21 AC 159 ms
56,136 KB
testcase_22 AC 189 ms
56,444 KB
testcase_23 AC 168 ms
55,628 KB
testcase_24 AC 150 ms
56,508 KB
testcase_25 AC 189 ms
56,292 KB
testcase_26 AC 190 ms
55,820 KB
testcase_27 AC 190 ms
56,660 KB
testcase_28 AC 141 ms
55,576 KB
testcase_29 AC 176 ms
56,124 KB
testcase_30 AC 140 ms
55,560 KB
testcase_31 AC 191 ms
56,264 KB
testcase_32 AC 143 ms
55,564 KB
testcase_33 AC 189 ms
56,068 KB
testcase_34 AC 144 ms
55,612 KB
testcase_35 AC 189 ms
55,772 KB
testcase_36 AC 177 ms
55,916 KB
testcase_37 AC 144 ms
55,676 KB
testcase_38 AC 156 ms
55,552 KB
testcase_39 AC 155 ms
55,816 KB
testcase_40 AC 190 ms
56,236 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