Created
February 23, 2019 12:53
-
-
Save ilyosdev/a9639a11267d42b352fe812997cf30aa to your computer and use it in GitHub Desktop.
Compare the Triplets
This file contains hidden or 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 | |
$_fp = fopen ("php://stdin","r"); | |
$a = explode(' ', trim(fgets($_fp))); | |
$b = explode(' ', trim(fgets($_fp))); | |
array_walk($a, function(&$value){$value = intval($value);}); | |
array_walk($b, function(&$value){$value = intval($value);}); | |
$pointsA = 0; | |
$pointsB = 0; | |
for ($i = 0; $i < count($a); $i++) { | |
if ($a[$i] > $b[$i]) $pointsA++; | |
elseif ($b[$i] > $a[$i]) $pointsB++; | |
} | |
echo $pointsA, ' ', $pointsB; | |
?> | |
mine: | |
<?php | |
function compareTriplets($a, $b) { | |
$el1=0; | |
$el2=0; | |
for($i=0; $i<3; $i++) | |
{ | |
if($a[$i]>$b[$i]) | |
{ | |
$el1 +=1; | |
} | |
if($a[$i]<$b[$i]) | |
{ | |
$el2 +=1; | |
} | |
} | |
return $el1.' '.$el2; | |
} | |
$a = array_map('intval', preg_split('/ /', $a_temp, -1, PREG_SPLIT_NO_EMPTY)); | |
$b_temp = rtrim(fgets(STDIN)); | |
$b = array_map('intval', preg_split('/ /', $b_temp, -1, PREG_SPLIT_NO_EMPTY)); | |
$result = compareTriplets($a, $b); | |
fwrite($fptr,$result. "\n"); | |
fclose($fptr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment