結果

問題 No.275 中央値を求めよ
ユーザー SATSUKI-UPDATESATSUKI-UPDATE
提出日時 2022-05-17 16:54:57
言語 PHP
(8.3.4)
結果
WA  
実行時間 -
コード長 892 bytes
コンパイル時間 883 ms
コンパイル使用メモリ 12,064 KB
実行使用メモリ 12,440 KB
最終ジャッジ日時 2023-10-13 14:55:06
合計ジャッジ時間 3,430 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
12,372 KB
testcase_01 AC 7 ms
12,288 KB
testcase_02 AC 8 ms
12,356 KB
testcase_03 WA -
testcase_04 AC 7 ms
12,356 KB
testcase_05 AC 7 ms
12,364 KB
testcase_06 AC 8 ms
12,388 KB
testcase_07 AC 21 ms
12,356 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 10 ms
12,300 KB
testcase_11 WA -
testcase_12 AC 8 ms
12,336 KB
testcase_13 WA -
testcase_14 AC 7 ms
12,352 KB
testcase_15 AC 49 ms
12,344 KB
testcase_16 AC 40 ms
12,324 KB
testcase_17 AC 40 ms
12,288 KB
testcase_18 AC 13 ms
12,328 KB
testcase_19 WA -
testcase_20 AC 29 ms
12,372 KB
testcase_21 AC 16 ms
12,352 KB
testcase_22 AC 35 ms
12,332 KB
testcase_23 WA -
testcase_24 AC 11 ms
12,360 KB
testcase_25 AC 42 ms
12,284 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 15 ms
12,276 KB
testcase_30 AC 8 ms
12,292 KB
testcase_31 AC 34 ms
12,348 KB
testcase_32 AC 9 ms
12,352 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 9 ms
12,312 KB
testcase_38 AC 10 ms
12,352 KB
testcase_39 WA -
testcase_40 AC 47 ms
12,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
function getStandardInput()
{
  $array = array();
  while (true) {
    $stdin = fgets(STDIN);
    if ($stdin == "") {
      break;
    }
    $array[] = rtrim($stdin);
  }
  return $array;
}

function splitBySpace($str)
{
  return explode(' ', $str);
}

function bubbleSort($array)
{
    $cnt = count($array);

    for($i=0;$i<$cnt-1;$i++){
        for($j=$i+1;$j<$cnt;$j++){
            if($array[$i]>$array[$j]){
                $tmp = $array[$i];
                $array[$i] = $array[$j];
                $array[$j] = $tmp;
            }
        }
    }
    return $array;
}

$stdIn = getStandardInput();
$time = $stdIn[0];
$input = splitBySpace($stdIn[1]);
$input = bubbleSort($input);
$result = 0;
$arrayCnt = count($input);
if($arrayCnt % 2 == 0){
    $result =($input[($arrayCnt/2)-1] + $input[($arrayCnt/2)]) / 2;
} else {
    $result = $input[$arrayCnt/2 + 0.5];
}
echo($result);
0