結果

問題 No.275 中央値を求めよ
ユーザー nekoziroo
提出日時 2018-05-30 13:40:24
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 562 bytes
コンパイル時間 12,419 ms
コンパイル使用メモリ 390,924 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-25 01:34:21
合計ジャッジ時間 13,725 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::stdin;

fn get_line() -> String {
    let mut line = String::new();
    stdin().read_line(&mut line).ok();
    line
}

fn main() {
    let n = get_line();
    let n: usize = n.trim().parse().unwrap();
    let line = get_line();
    let line: Vec<&str> = line.trim().split_whitespace().collect();
    let mut a: Vec<i32> = line.iter().map(|x| x.parse().unwrap()).collect();
    a.sort();

    if a.len() % 2 == 1 {
        println!("{}", a[n / 2] as f32);
    } else {
        println!("{}", (a[(n - 1) / 2] as f32 + a[n / 2] as f32) / 2.0);
    }
}
0