fork(4) download
  1. <?php
  2.  
  3.  
  4. $amount = 54500;
  5.  
  6. $bills = array(
  7. 100 => 23,
  8. 500 => 5,
  9. 1000 => 0,
  10. 5000 => 200
  11. );
  12. $bills = array_reverse($bills, TRUE);
  13. $array = array();
  14. echo "Сумма: $amount\n";
  15. function giveMoney($bills, $amount){
  16. if ($amount > 0 and $amount % 100 == 0) {
  17. foreach ($bills as $nominal => $value) {
  18. $countBanknote = floor($amount / $nominal);
  19. if($amount >= $nominal and $countBanknote <= $value) {
  20. $value = $value - $countBanknote;
  21. $amount = $amount % $nominal;
  22. $return = "{$nominal}x{$countBanknote}";
  23. $array[] = $return;
  24. }if($value == 0 and $countBanknote != 0) {
  25. }
  26. if($amount >= $nominal and $countBanknote > $value and $value != 0) {
  27. $countBanknote = $value;
  28. $sum = $nominal * $countBanknote;
  29. $amount = $amount % $sum;
  30. $return = "{$nominal}x{$countBanknote}";
  31. $array[] = $return;
  32. }
  33.  
  34. }
  35. $array = implode(" ", $array);
  36. echo "Выдача возможна, число купюр:\n$array\n";
  37. }if($amount < 0) {
  38. echo"Выдача невозможна: сумма меньша нуля.\n";
  39. }if($amount % 100 != 0) {
  40. echo"Выдача невозможна: Сумма не кратна 100.\n";
  41. }
  42. }
  43. giveMoney($bills, $amount);
Success #stdin #stdout 0s 82560KB
stdin
Standard input is empty
stdout
Сумма: 54500
Выдача возможна, число купюр:
5000x10 500x5 100x20