結果

問題 No.275 中央値を求めよ
ユーザー mahna
提出日時 2020-05-16 22:22:32
言語 PHP
(843.2)
結果
WA  
実行時間 -
コード長 427 bytes
コンパイル時間 3,345 ms
コンパイル使用メモリ 30,712 KB
実行使用メモリ 31,628 KB
最終ジャッジ日時 2024-09-22 21:04:03
合計ジャッジ時間 6,038 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other AC * 2 WA * 36
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php

    $input = trim(fgets(STDIN));
    $num = explode(" ",$input);
    
    sort($num);
    if (count($num) % 2 == 1) {
        $med_key = array_key_last($num) / 2;
        echo $num[$med_key];
    } else {
        $med_key_before = floor(array_key_last($num) / 2);
        $med_key_after = $med_key_before + 1;
        
        $ans = ($num[$med_key_before] + $num[$med_key_after]) / 2;
        echo $ans;
    }
    

?>
0