結果
| 問題 |
No.32 貯金箱の憂鬱
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-25 23:47:46 |
| 言語 | PHP (843.2) |
| 結果 |
AC
|
| 実行時間 | 43 ms / 5,000 ms |
| コード長 | 976 bytes |
| コンパイル時間 | 1,185 ms |
| コンパイル使用メモリ | 32,532 KB |
| 実行使用メモリ | 31,376 KB |
| 最終ジャッジ日時 | 2024-07-23 07:59:44 |
| 合計ジャッジ時間 | 2,288 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
コンパイルメッセージ
No syntax errors detected in Main.php
ソースコード
<?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);
}