<?php
$amout = 6600;
100 => 0,
200 => 3,
500 => 1,
1000 => 0,
2000 => 4,
5000 => 1
);
$summBills = $bills[100] * 100 + $bills[200] * 200 + $bills[500] * 500 + $bills[1000] * 1000 + $bills[2000] * 2000 + $bills[5000] * 5000; //общее кол-во денег
$str = "Выдача возможна, число купюр:\n";
function checkBills ($bill, &$bills, &$amout, &$str) {
if (floor($amout / $bill) >= $bills[$bill]) { //проверка, сколько можно выдать купюр и хватит ли их $str = $str . $bills[$bill] . "x{$bill} "; //если нет, то выдаются оставшиеся ну и обнуляется
$amout = $amout - $bills[$bill] * $bill; //их количество
$bills[$bill] = 0;
}
else {
echo floor($amout / $bill) . "x{$bill} "; $str = $str . floor($amout / $bill) . "x{$bill} "; $amoutTemp = $amout - floor($amout / $bill) * $bill; //количество выданых $bills[$bill] = $bills[$bill] - floor($amout / $bill); $amout = $amoutTemp;
}
}
//проверки всякие
echo "Сумма: {$amout}\n";
if ($amout <= 0) {echo "Введенная сума некоректна.";}
else if (($amout % 100) != 0) {
echo "Выдача меньше купюр 100р не возможна, введите число кратное 100";
}
else if ($amout > $summBills) {
echo "Не хватает денег в банкомате, максимально возможная сумма выдачи {$summBills}";
}
else {
if (($amout >= 5000) && ($bills[5000] > 0)) {
checkBills(5000, $bills, $amout, $str);
}
if (($amout >= 2000) && ($bills[2000] > 0)) {
checkBills(2000, $bills, $amout, $str);
}
if ($amout >= 1000 && ($bills[1000] > 0)) {
checkBills(1000, $bills, $amout, $str);
}
if ($amout >= 500 && ($bills[500] > 0)) {
checkBills(500, $bills, $amout, $str);
}
if ($amout >= 200 && ($bills[200] > 0)) {
checkBills(200, $bills, $amout, $str);
}
if ($amout >= 100 && ($bills[100] > 0)) {
checkBills(100, $bills, $amout, $str);
}
}
echo "{$str}";
?>
PD9waHAKCWVycm9yX3JlcG9ydGluZygtMSk7CgkKCQkkYW1vdXQgPSA2NjAwOwogICAgICAgICRiaWxscyA9IGFycmF5KAoJCTEwMCA9PiAwLAoJCTIwMCA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