0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AtCoder160(ABC)の B問題を解いた(PHP)

Last updated at Posted at 2022-08-27

問題文の要点:
高橋君が持っている "500 円硬貨 1 枚につき 1000"、5 円硬貨 1 枚につき 5 の 嬉しさ を得ます。
高橋君の嬉しさが最大になるように両替したとき、高橋君の嬉しさはいくらになりますか?

<?php
$X = trim(fgets(STDIN));
$fiveHundredCount = 0; //500円玉の枚数
$fiveCount = 0; //5円玉の枚数
$num = $X; //一時的に計算する場所
$ans = 0; //解答
if ($X >= 500) {
    $fiveHundredCount = floor($num / 500); //500円玉の枚数を求める
    $num = $num - (500 * $fiveHundredCount);/*標準入力の数値から500円の枚数分を引き、
                                              残りの金額を出す(500円玉を最大枚数分使う)。*/
    $fiveCount = floor($num / 5); //5円玉の枚数を求める
    $ans = ($fiveHundredCount * 1000) + ($fiveCount * 5); // 嬉しさを両替する
    echo $ans;
} elseif ($X == 0) {
    echo 0;
} else {
    $fiveCount = floor($num / 5); //5円玉の枚数を求める
    $ans = $fiveCount * 5; //嬉しさを両替する。
    echo $ans;
}

0
0
2

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?