結果

問題 No.275 中央値を求めよ
ユーザー fal_rnd
提出日時 2017-04-02 21:12:00
言語 Java
(openjdk 23)
結果
AC  
実行時間 182 ms / 1,000 ms
コード長 579 bytes
コンパイル時間 2,019 ms
コンパイル使用メモリ 75,200 KB
実行使用メモリ 42,600 KB
最終ジャッジ日時 2024-06-25 00:26:36
合計ジャッジ時間 9,531 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main{

	static final Scanner s=new Scanner(System.in);

	public static void main(String args[]){
		input();
		solve();
	}

	private static void input(){
	}
	private static void solve(){
		int n=s.nextInt(),in[]=new int[n];
		for(int i=0;i<n;i++)
			in[i]=s.nextInt();
		Arrays.sort(in);

		System.out.println(getMedian(in));
	}
	public static double getMedian(int[]/*SORTED ARRAY*/ in) {
		if(in.length%2==0) {
			return ((double)in[in.length/2-1]+in[in.length/2])/2;
		}else {
			return in[in.length/2];
		}
	}
}
0