結果

問題 No.275 中央値を求めよ
ユーザー seinyan
提出日時 2021-11-15 20:23:08
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 496 bytes
コンパイル時間 11,029 ms
コンパイル使用メモリ 403,440 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-15 03:46:35
合計ジャッジ時間 12,323 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let n: usize = input_line()[0];
    let mut a: Vec<i32> = input_line();

    a.sort();
    if a.len() % 2 != 0 {
        println!("{}", a[n / 2]);
        return;
    }

    println!("{}", (a[n / 2 - 1] + a[n / 2]) as f64 / 2.0);
}

#[allow(unused)]
fn input_line<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
0