fork download
  1. <?php
  2. // Staring straight up into the sky ... oh my my
  3.  
  4. $amount = 54500;
  5. $bills = array(
  6. 100 => 23,
  7. 500 => 5,
  8. 1000 => 0,
  9. 5000 => 200
  10. );
  11.  
  12. $result = array_fill_keys(array_keys($bills), 0);
  13.  
  14. krsort($bills);
  15. foreach($bills as $key => $value){
  16. $flg = true;
  17. while($value>0 && $flg){
  18. if(($amount - $key)<0){
  19. $flg = false;
  20. }else{
  21. $amount -= $key;
  22. $value--;
  23. $result[$key]++;
  24. }
  25. }
  26. }
  27.  
  28. $resultStr = "";
  29. foreach ($result as $key => $value) {
  30. if($value != 0){
  31. $resultStr = $resultStr."{$value}x{$key} ";
  32. }
  33. }
  34. echo $resultStr."\n";
  35.  
  36. ?>
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
20x100 5x500 10x5000