結果

問題 No.275 中央値を求めよ
ユーザー penguinshunya
提出日時 2017-12-31 19:10:15
言語 Rust
(1.83.0 + proconio)
結果
RE  
実行時間 -
コード長 591 bytes
コンパイル時間 12,426 ms
コンパイル使用メモリ 402,320 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-21 15:32:15
合計ジャッジ時間 13,882 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 4 RE * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `n`
 --> src/main.rs:2:9
  |
2 |     let n = read::<u32>();
  |         ^ help: if this is intentional, prefix it with an underscore: `_n`
  |
  = note: `#[warn(unused_variables)]` on by default

ソースコード

diff #

fn main() {
    let n = read::<u32>();
    let mut a = read_vec::<u32>();
    a.sort();
    let a:Vec<f64> = a.into_iter().map(|n|n as f64).collect();
    if a.len() % 2 == 1 {
        println!("{}", a[a.len()/2]);
    } else {
        println!("{}", (a[a.len()/2]+a[a.len()/2-1])/2f64);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
0