Created
September 16, 2017 22:35
-
-
Save allurco/1a9f5f720f7b5a61083d1eadb82c947d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$handle = fopen ("php://stdin","r"); | |
fscanf($handle,"%d",$n); | |
$unsorted = array(); | |
for($unsorted_i = 0; $unsorted_i < $n; $unsorted_i++){ | |
fscanf($handle,"%s",$unsorted[]); | |
} | |
// your code goes here | |
function sortArr($arr) { | |
if (count($arr) == 1) { | |
echo $arr[0]; | |
die(); | |
} | |
$mArr = $arr; | |
for ($i=0;$i<count($arr);$i++) { | |
for ($z=0;$z<count($arr);$z++) { | |
//var_dump($arr[$i]); | |
//var_dump($arr[$z]); | |
if ($arr[$i] <= $arr[$z]) { | |
$ress = true; | |
} else { | |
$ress = false; | |
break; | |
} | |
} | |
//var_dump("..."); | |
if ($ress) { | |
echo $arr[$i]."\n"; | |
array_splice($mArr, $i, 1); | |
//var_dump($mArr); | |
sortArr($mArr); | |
} | |
} | |
} | |
sortArr($unsorted); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment