結果

問題 No.275 中央値を求めよ
ユーザー oyafuso
提出日時 2019-03-11 16:56:17
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 938 bytes
コンパイル時間 2,157 ms
コンパイル使用メモリ 86,064 KB
実行使用メモリ 56,440 KB
最終ジャッジ日時 2024-06-23 15:37:58
合計ジャッジ時間 9,251 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main {

	private static final String SPLIT_STR = " ";

	public static void main(String[] args) {
		// Scanner生成
		Scanner sc = new Scanner(System.in);
		// 入力設定
		String input = sc.nextLine();
		sc.reset();
		input = sc.nextLine();
		String[] split = input.split(SPLIT_STR);
		List<Integer> numList = new ArrayList<>(split.length);
		for (int i = 0; i < split.length; i++) {
			numList.add(Integer.parseInt(split[i]));
		}
		// Scannerクローズ
		sc.close();

		/* メイン処理開始 */
		// 変数初期化
		double result = 0;
		int middleIndex = numList.size() / 2;
		// 結果設定
		Collections.sort(numList);
		result = numList.get(middleIndex);
		System.out.println(result);
		if (numList.size() % 2 == 0) {
			result += numList.get(middleIndex - 1);
		System.out.println(result);
			result /= 2;
		}
		/* メイン処理終了 */

		// 結果出力
		System.out.println(result);
	}
}
0