結果
| 問題 |
No.275 中央値を求めよ
|
| ユーザー |
|
| 提出日時 | 2019-10-14 00:04:13 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 660 bytes |
| コンパイル時間 | 16,054 ms |
| コンパイル使用メモリ | 398,716 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-17 19:44:20 |
| 合計ジャッジ時間 | 13,469 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
ソースコード
use std::io::{self, Read};
fn read_stdin() -> Vec<String> {
let mut buffer = String::new();
io::stdin().read_to_string(&mut buffer).ok();
buffer.trim().split('\n').map(|s| s.to_string()).collect()
}
fn main() {
let input = read_stdin();
let n = &input[0].parse::<usize>().unwrap();
let mut nums = input[1].split(' ').map(|s| s.parse::<isize>().unwrap()).collect::<Vec<isize>>();
nums.sort();
let result: f64 = if n % 2 == 1 {
*&nums[*n / 2] as f64
} else {
let r = &nums[*n / 2 - 1..*n / 2 + 1];
let total = r.iter().sum::<isize>() as f64;
total / 2.0
};
println!("{}", result);
}