問題
PHPで解いています。
解答
<?php
$x = intval(trim(fgets(STDIN)));
if($x % 10 === 0){
$result = $x / 10;
} elseif ($x > 0){
$result = intdiv($x, 10) + 1;
} else {
$result = intdiv($x, 10);
}
echo $result.PHP_EOL;
つまづいたポイント
正の整数、負の整数それぞれの切り上げ方法
正の場合:単純に入力値を10で割ってしまうと切り捨てになってしまうので+1をする。
$result = intdiv($x, 10) + 1;
負の場合:整数の商そのものが切り上げとなるため、単に整数の商を求める。
$result = intdiv($x, 10);