fork download
  1. <?php
  2.  
  3. function generateHistogram($scores) {
  4. $histogram = array_fill(0, 10, 0);
  5. foreach ($scores as $score) {
  6. if ($score >= 0 && $score <= 100) {
  7. $index = ($score == 100) ? 9 : floor($score / 10);
  8. $histogram[$index]++;
  9. }
  10. }
  11. return $histogram;
  12. }
  13.  
  14. $input = trim(fgets(STDIN));
  15. $scores = array_map('intval', explode(' ', $input));
  16. $histogram = generateHistogram($scores);
  17.  
  18. for ($i = 0; $i < count($histogram); $i++) {
  19. $startRange = $i * 10;
  20. $endRange = ($i == 9) ? 100 : $startRange + 9;
  21. echo "$startRange-$endRange: " . $histogram[$i] . "\n";
  22. }
  23.  
  24. ?>
Success #stdin #stdout 0.02s 25616KB
stdin
Standard input is empty
stdout
0-9: 1
10-19: 0
20-29: 0
30-39: 0
40-49: 0
50-59: 0
60-69: 0
70-79: 0
80-89: 0
90-100: 0