fork(1) download
  1. <?php
  2.  
  3.  
  4. $amount = 6600;
  5. $bills = array(
  6. 100 => 23,
  7. 200 => 3,
  8. 500 => 1,
  9. 1000 => 0,
  10. 2000 => 4,
  11. 5000 => 1
  12. );
  13. $bills = array_reverse($bills, true);
  14. //var_dump($bills);
  15. echo "Выдача возможна, число купюр:\n";
  16. foreach ($bills as $nominal => $number) {
  17. $quantity = floor($amount / $nominal);
  18. if ($number >= $quantity) {
  19. $amount = $amount - ($quantity * $nominal);
  20. $delivery = $quantity;
  21. }
  22. else {
  23. $amount = $amount - ($number * $nominal);
  24. $delivery = $number;
  25. }
  26. $x = 'x';
  27. echo "$delivery$x$nominal ";
  28. }
  29.  
  30.  
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Выдача возможна, число купюр:
1x5000 0x2000 0x1000 1x500 3x200 5x100