結果
問題 | No.275 中央値を求めよ |
ユーザー |
|
提出日時 | 2022-05-17 16:56:16 |
言語 | PHP (843.2) |
結果 |
AC
|
実行時間 | 87 ms / 1,000 ms |
コード長 | 892 bytes |
コンパイル時間 | 3,558 ms |
コンパイル使用メモリ | 30,552 KB |
実行使用メモリ | 30,988 KB |
最終ジャッジ日時 | 2024-09-15 11:42:16 |
合計ジャッジ時間 | 6,951 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
コンパイルメッセージ
No syntax errors detected in Main.php
ソースコード
<?phpfunction 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);