結果

問題 No.275 中央値を求めよ
ユーザー Lo_OT
提出日時 2018-03-22 22:42:59
言語 Java
(openjdk 23)
結果
AC  
実行時間 198 ms / 1,000 ms
コード長 1,305 bytes
コンパイル時間 3,899 ms
コンパイル使用メモリ 78,752 KB
実行使用メモリ 43,384 KB
最終ジャッジ日時 2024-06-25 01:03:36
合計ジャッジ時間 10,756 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.Collections;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Yukicoder solver = new Yukicoder();
        solver.solve(1, in, out);
        out.close();
    }

    static class Yukicoder {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int loops = in.nextInt();
            List<Integer> arr = new ArrayList<Integer>();

            for (int i = 0; i < loops; i++) {
                arr.add(in.nextInt());
            }
            Collections.sort(arr);


            if (loops % 2 == 0) {
                int median = loops / 2;
                out.println((arr.get(median - 1) + arr.get(median)) / 2.0);
            } else {
                int median = (int) Math.floor(loops / 2);
                out.println(arr.get(median));
            }
        }

    }
}

0