<?php
$result ='';
$count = 0;
$amount = 600;
5000 => 200,
1000 => 0,
500 => 5,
100 => 0
);
echo "Сумма: {$amount}\n";
if($amount % 100 != 0){
echo "Выдача невозможна : сумма не кратна 100\n";
}elseif($amount < 0){
echo "Выдача невозможна : сумма меншье 0\n";
}else{
foreach($bills as $faceValue => $quantity){
$possibleQuantity = floor($amount / $faceValue); if($quantity == 0 || $amount < $faceValue){
}elseif($possibleQuantity <= $quantity){
$amount = $amount - ($possibleQuantity * $faceValue);
$result.= "{$possibleQuantity}x{$faceValue} ";
}elseif($possibleQuantity >= $quantity){
$amount = $amount - ($quantity * $faceValue);
$result.= "{$quantity}x{$faceValue} ";
}
}
if($amount != 0){
echo "Выдача невозможна : в банкомате недостаточно купюр\n";
}else{
echo "Выдача возможна, число купюр:\n";
echo $result;
}
}
PD9waHAKIAplcnJvcl9yZXBvcnRpbmcoLTEpOwptYl9pbnRlcm5hbF9lbmNvZGluZygndXRmLTgnKTsKJHJlc3VsdCA9Jyc7CiRjb3VudCA9IDA7CiRhbW91bnQgPSA2MDA7CiRiaWxscyA9IGFycmF5KAoJNTAwMCA9PiAyMDAsCgkxMDAwID0+IDAsCgk1MDAgPT4gNSwKCTEwMCA9PiAwCik7CmVjaG8gItCh0YPQvNC80LA6IHskYW1vdW50fVxuIjsKaWYoJGFtb3VudCAlIDEwMCAhPSAwKXsKCWVjaG8gItCS0YvQtNCw0YfQsCDQvdC10LLQvtC30LzQvtC20L3QsCA6INGB0YPQvNC80LAg0L3QtSDQutGA0LDRgtC90LAgMTAwXG4iOwp9ZWxzZWlmKCRhbW91bnQgPCAwKXsKCWVjaG8gItCS0YvQtNCw0YfQsCDQvdC10LLQvtC30LzQvtC20L3QsCA6INGB0YPQvNC80LAg0LzQtdC90YjRjNC1IDBcbiI7Cn1lbHNlewoJZm9yZWFjaCgkYmlsbHMgYXMgJGZhY2VWYWx1ZSA9PiAkcXVhbnRpdHkpewoJCSRwb3NzaWJsZVF1YW50aXR5ID0gZmxvb3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