Created
April 5, 2020 12:13
-
-
Save stmkza/e24c212b4401087f915271c04df2226d 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 | |
[$s, $l, $r] = explode(' ', file_get_contents('php://stdin')); | |
if($l <= $s && $s <= $r) printf("%d\n", $s); | |
else if($l > $s) printf("%d\n", $l); | |
else printf("%d\n", $r); |
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 | |
[$s, $l, $r] = explode(' ', file_get_contents('php://stdin')); | |
$x = $s; | |
while(!isStopPosition($x, $l, $r)) { | |
if($x < $l) $x += 1; | |
else if($x > $r) $x -= 1; | |
} | |
printf("%d\n", $x); | |
function isStopPosition($pos, $l, $r): bool | |
{ | |
return $l <= $pos && $pos <= $r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment