結果

問題 No.275 中央値を求めよ
ユーザー yamax3232yamax3232
提出日時 2017-02-16 16:01:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 318 ms / 1,000 ms
コード長 966 bytes
コンパイル時間 5,421 ms
コンパイル使用メモリ 74,420 KB
実行使用メモリ 63,320 KB
最終ジャッジ日時 2023-09-07 05:54:47
合計ジャッジ時間 16,731 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 143 ms
56,036 KB
testcase_01 AC 143 ms
55,700 KB
testcase_02 AC 184 ms
56,768 KB
testcase_03 AC 143 ms
56,116 KB
testcase_04 AC 143 ms
56,012 KB
testcase_05 AC 145 ms
55,912 KB
testcase_06 AC 168 ms
56,400 KB
testcase_07 AC 258 ms
60,700 KB
testcase_08 AC 213 ms
57,652 KB
testcase_09 AC 208 ms
56,204 KB
testcase_10 AC 216 ms
56,664 KB
testcase_11 AC 144 ms
56,400 KB
testcase_12 AC 143 ms
55,976 KB
testcase_13 AC 143 ms
55,896 KB
testcase_14 AC 144 ms
56,076 KB
testcase_15 AC 318 ms
61,680 KB
testcase_16 AC 312 ms
61,524 KB
testcase_17 AC 300 ms
61,400 KB
testcase_18 AC 249 ms
60,644 KB
testcase_19 AC 273 ms
60,236 KB
testcase_20 AC 279 ms
60,652 KB
testcase_21 AC 252 ms
60,164 KB
testcase_22 AC 290 ms
61,368 KB
testcase_23 AC 259 ms
60,584 KB
testcase_24 AC 222 ms
59,244 KB
testcase_25 AC 311 ms
61,564 KB
testcase_26 AC 301 ms
61,672 KB
testcase_27 AC 273 ms
60,780 KB
testcase_28 AC 177 ms
56,432 KB
testcase_29 AC 253 ms
60,548 KB
testcase_30 AC 178 ms
55,996 KB
testcase_31 AC 298 ms
61,484 KB
testcase_32 AC 205 ms
56,312 KB
testcase_33 AC 282 ms
63,320 KB
testcase_34 AC 177 ms
56,204 KB
testcase_35 AC 271 ms
59,972 KB
testcase_36 AC 251 ms
60,300 KB
testcase_37 AC 218 ms
56,600 KB
testcase_38 AC 220 ms
59,788 KB
testcase_39 AC 241 ms
60,300 KB
testcase_40 AC 300 ms
62,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Q2 {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner kb=new Scanner(System.in);
		int n=kb.nextInt();
		double ar[]=new double[n];
		double num;
		for(int i=0;i<n;i++){
			ar[i]=kb.nextDouble();
		}
		//並べ替え
for(int j=0;j<n;j++){
		for(int i=0;i<n;i++){
			if(i+1<n){
				num=0;
				if(ar[i]>ar[i+1]){
					num=ar[i];
					ar[i]=ar[i+1];
					ar[i+1]=num;
				}else{
					continue;
				}
			}else{
				break;
			}
		}
	}

	/*	for(int i=0;i<n;i++){
			System.out.printf("%d",ar[i]);
		}
		ちゃんと並べ替えられていることを確認*/

		if(n%2==0){
			double a=ar[n/2-1]+ar[n/2];
			try{
			System.out.printf("%f",
					a/2);
			}catch(NumberFormatException e){
				System.out.printf("%f",a/2);
			}
			
		}else{
			try{
			System.out.printf("%f",ar[n/2]);
			}catch(NumberFormatException e){
				System.out.printf("%f",ar[n/2]);
			}
		}

	}

}
0