codingame/FACILE/Températures/script.php
2015-03-02 19:42:39 +01:00

46 lines
902 B
PHP

<?php
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
fscanf(STDIN, "%d",
$N // the number of temperatures to analyse
);
$TEMPS = explode(' ', stream_get_line(STDIN, 256, "\n")); // the N temperatures expressed as integers ranging from -273 to 5526
$key = null;
$diff = null;
if (count($TEMPS) === 1) {
echo "0\n";
}
foreach ($TEMPS as $k => $v) {
$d = abs((int) $v);
if ($diff === null) {
$key = $k;
$diff = $d;
continue;
}
if ($d === $diff && $v > $TEMPS[$key]) {
$key = $k;
$diff = $d;
continue;
}
if ($d < $diff) {
$key = $k;
$diff = $d;
}
}
// Write an action using echo(). DON'T FORGET THE TRAILING \n
// To debug (equivalent to var_dump): error_log(var_export($var, true));
echo $TEMPS[$key], "\n";
?>