0
0

【AtCoder】備忘録345-B

Posted at

問題

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);
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0