結果

問題 No.275 中央値を求めよ
ユーザー aaaaasatori
提出日時 2018-02-05 08:59:39
言語 Java
(openjdk 23)
結果
RE  
実行時間 -
コード長 567 bytes
コンパイル時間 3,505 ms
コンパイル使用メモリ 75,396 KB
実行使用メモリ 56,556 KB
最終ジャッジ日時 2024-07-06 09:32:58
合計ジャッジ時間 9,434 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other AC * 6 WA * 28 RE * 4
権限があれば一括ダウンロードができます

ソースコード

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 / 2 + 1]);
		}else {
			System.out.println((float)(t[n / 2] + t[n / 2 + 1]) / 2);
		}
	}
}
0