結果

問題 No.32 貯金箱の憂鬱
ユーザー sorchsorch
提出日時 2020-07-25 23:47:46
言語 PHP
(8.3.4)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 976 bytes
コンパイル時間 62 ms
コンパイル使用メモリ 12,116 KB
実行使用メモリ 12,320 KB
最終ジャッジ日時 2023-09-30 13:57:28
合計ジャッジ時間 756 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
12,284 KB
testcase_01 AC 8 ms
12,312 KB
testcase_02 AC 8 ms
12,304 KB
testcase_03 AC 7 ms
12,204 KB
testcase_04 AC 7 ms
12,216 KB
testcase_05 AC 7 ms
12,216 KB
testcase_06 AC 8 ms
12,232 KB
testcase_07 AC 8 ms
12,320 KB
testcase_08 AC 8 ms
12,312 KB
testcase_09 AC 8 ms
12,228 KB
testcase_10 AC 7 ms
12,312 KB
testcase_11 AC 8 ms
12,252 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php

/**
 * No.32 貯金箱の憂鬱
 * 
 * @see https://yukicoder.me/problems/5
 */

const CURRENCY_UNIT_LIST = [1000, 100, 25, 1];

$numOfCoinHandred = trim(fgets(STDIN));
$numOfCoinTwentyFive = trim(fgets(STDIN));
$numOfCoinOne = trim(fgets(STDIN));

$total = CURRENCY_UNIT_LIST[1] * $numOfCoinHandred
    + CURRENCY_UNIT_LIST[2] * $numOfCoinTwentyFive
    + CURRENCY_UNIT_LIST[3] * $numOfCoinOne;
excangeMoney($total, CURRENCY_UNIT_LIST, $results);
// echo implode(",", $results) . "\n";

$numOfCoin = $results[1] + $results[2] + $results[3];

// 出力
echo $numOfCoin . "\n";


function excangeMoney($total, $currencyUnitList, &$numListOfEachUnit)
{
    rsort($currencyUnitList);
    if (count($currencyUnitList) == 0) {
        return;
    }
    $targetUnit = array_shift($currencyUnitList);
    $num = floor($total / $targetUnit);
    $numListOfEachUnit[] = $num;

    $total -= $targetUnit * $num;
    excangeMoney($total, $currencyUnitList, $numListOfEachUnit);
}
0