<?php
$amount = 54500; //требуемая сумма
100 => 23,
500 => 5,
1000 => 0,
5000 => 200
); //запас наличных
function giveMeMyMoney($amount, $array, $bill)
{
static $quantity = "Выдача возможна, число купюр:\n";
$needed = floor($amount / $bill); if ($needed <= $array[$bill])
{
$amount -= $needed * $bill;
$quantity .= "{$needed}x$bill ";
}
else
{
$amount -= $array[$bill] * $bill;
$quantity .= "{$array[$bill]}x$bill ";
}
if ($bill == 5000)
giveMeMyMoney($amount, $array, 1000);
elseif ($bill == 1000)
giveMeMyMoney($amount, $array, 500);
elseif ($bill == 500)
giveMeMyMoney($amount, $array, 100);
elseif ($bill == 100 && $amount > 0)
echo "Выдача невозможна: недостаточно купюр.";
else
echo $quantity;
}
echo "Сумма: {$amount}\n";
if ($amount <= 100)
echo "Выдача невозможна: слишком маленькое число.";
elseif (($amount % 100) != 0)
echo "Выдача невозможна: сумма не кратна 100.";
else
giveMeMyMoney($amount, $bills, 5000);
PD9waHAKZXJyb3JfcmVwb3J0aW5nKC0xKTsKJGFtb3VudCA9IDU0NTAwOyAvL9GC0YDQtdCx0YPQtdC80LDRjyDRgdGD0LzQvNCwCiRiaWxscyAgPSBhcnJheSgKICAgIDEwMCA9PiAyMywKICAgIDUwMCA9PiA1LAogICAgMTAwMCA9PiAwLAogICAgNTAwMCA9PiAyMDAKKTsgLy/Qt9Cw0L/QsNGBINC90LDQu9C40YfQvdGL0YUKCmZ1bmN0aW9uIGdpdmVNZU15TW9uZXkoJGFtb3VudCwgJGFycmF5LCAkYmlsbCkKICB7CiAgICBzdGF0aWMgJHF1YW50aXR5ID0gItCS0YvQtNCw0YfQsCDQstC+0LfQvNC+0LbQvdCwLCDRh9C40YHQu9C+INC60YPQv9GO0YA6XG4iOwogICAgJG5lZWRlZCA9IGZsb29yKCRhbW91bnQgLyAkYmlsbCk7CiAgICBpZiAoJG5lZWRlZCA8PSAkYXJyYXlbJGJpbGxdKQogICAgICB7CiAgICAgICAgJGFtb3VudCAtPSAkbmVlZGVkICogJGJpbGw7CiAgICAgICAgJHF1YW50aXR5IC49ICJ7JG5lZWRlZH14JGJpbGwgIjsKICAgICAgfQogICAgZWxzZQogICAgICB7CiAgICAgICAgJGFtb3VudCAtPSAkYXJyYXlbJGJpbGxdICogJGJpbGw7CiAgICAgICAgJHF1YW50aXR5IC49ICJ7JGFycmF5WyRiaWxsXX14JGJpbGwgIjsKICAgICAgfQogICAgCiAgICBpZiAoJGJpbGwgPT0gNTAwMCkKICAgICAgICBnaXZlTWVNeU1vbmV5KCRhbW91bnQsICRhcnJheSwgMTAwMCk7CiAgICBlbHNlaWYgKCRiaWxsID09IDEwMDApCiAgICAgICAgZ2l2ZU1lTXlNb25leSgkYW1vdW50LCAkYXJyYXksIDUwMCk7CiAgICBlbHNlaWYgKCRiaWxsID09IDUwMCkKICAgICAgICBnaXZlTWVNeU1vbmV5KCRhbW91bnQsICRhcnJheSwgMTAwKTsKICAgIGVsc2VpZiAoJGJpbGwgPT0gMTAwICYmICRhbW91bnQgPiAwKQogICAgICAgIGVjaG8gItCS0YvQtNCw0YfQsCDQvdC10LLQvtC30LzQvtC20L3QsDog0L3QtdC00L7RgdGC0LDRgtC+0YfQvdC+INC60YPQv9GO0YAuIjsKICAgIGVsc2UKICAgICAgICBlY2hvICRxdWFudGl0eTsKICB9CmVjaG8gItCh0YPQvNC80LA6IHskYW1vdW50fVxuIjsKaWYgKCRhbW91bnQgPD0gMTAwKQogICAgZWNobyAi0JLRi9C00LDRh9CwINC90LXQstC+0LfQvNC+0LbQvdCwOiDRgdC70LjRiNC60L7QvCDQvNCw0LvQtdC90YzQutC+0LUg0YfQuNGB0LvQvi4iOwplbHNlaWYgKCgkYW1vdW50ICUgMTAwKSAhPSAwKQogICAgZWNobyAi0JLRi9C00LDRh9CwINC90LXQstC+0LfQvNC+0LbQvdCwOiDRgdGD0LzQvNCwINC90LUg0LrRgNCw0YLQvdCwIDEwMC4iOwplbHNlCiAgICBnaXZlTWVNeU1vbmV5KCRhbW91bnQsICRiaWxscywgNTAwMCk7