結果

問題 No.275 中央値を求めよ
ユーザー aaaaasatori
提出日時 2018-02-05 09:10:46
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 584 bytes
コンパイル時間 3,088 ms
コンパイル使用メモリ 74,664 KB
実行使用メモリ 54,928 KB
最終ジャッジ日時 2024-07-06 11:19:03
合計ジャッジ時間 9,595 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 24 WA * 13 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class No275 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(); // 整数の個数
		int t[] = new int[n];
		int x; //交換用
		
		for(int i = 0;i < n;i++) {
			t[i] = sc.nextInt();
		}
		
		for(int i = 0;i < n;i++) {
			for(int j = i + 1;j < n;j++) {
				if(t[i] > t[j]) {
					x = t[i];
					t[i] = t[j];
					t[j] = x;
				}
			}
		}
		
		if(n % 2 == 1) {
			System.out.println(t[(n - 1) / 2 + 1]);
		}else {
			System.out.println((float)(t[(n - 1) / 2] + t[(n - 1) / 2 + 1]) / 2);
		}
	}
}
0