結果
| 問題 |
No.275 中央値を求めよ
|
| ユーザー |
|
| 提出日時 | 2022-05-17 16:54:57 |
| 言語 | PHP (843.2) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 892 bytes |
| コンパイル時間 | 4,612 ms |
| コンパイル使用メモリ | 30,800 KB |
| 実行使用メモリ | 31,516 KB |
| 最終ジャッジ日時 | 2024-09-15 11:40:43 |
| 合計ジャッジ時間 | 7,135 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 24 WA * 14 |
コンパイルメッセージ
No syntax errors detected in Main.php
ソースコード
<?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);