結果
問題 | No.275 中央値を求めよ |
ユーザー |
![]() |
提出日時 | 2018-10-26 14:49:26 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 1,000 ms |
コード長 | 620 bytes |
コンパイル時間 | 12,557 ms |
コンパイル使用メモリ | 389,908 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-25 01:58:53 |
合計ジャッジ時間 | 13,934 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
fn main() {let mut input = String::new();std::io::stdin().read_line(&mut input).unwrap();input = String::new();std::io::stdin().read_line(&mut input).unwrap();let nums = input.trim().split_whitespace();let mut v: Vec<i32> = Vec::new();for i in nums {v.push(i.parse::<i32>().unwrap());}v.sort_by(|a, b| a.cmp(b));let length = v.len();let median: f32;if length % 2 == 0 {median = (v[(length / 2) - 1] as f32 + v[length / 2] as f32) / 2.0;}else {median = v[length / 2] as f32;}println!("{}", median);}