Advertisement
ShadowEmbrace

Student Academy

Nov 12th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.68 KB | None | 0 0
  1. <?php
  2.  
  3. $n = intval(readline());
  4. $studentGrades = [];
  5.  
  6. for ($i = 0; $i < 2 * $n; $i++) {
  7.     $input[] = readline();
  8.     if ($i === 0 || $i % 2 === 0) {
  9.         if (!key_exists($input[$i], $studentGrades)) {
  10.             $studentGrades[$input[$i]] = [];
  11.         }
  12.     } else {
  13.         array_push($studentGrades[$input[$i - 1]], floatval($input[$i]));
  14.     }
  15. }
  16.  
  17. foreach ($studentGrades as $student => $grade) {
  18.     $studentGrades[$student] = array_sum($studentGrades[$student]) / count($studentGrades[$student]);
  19. }
  20.  
  21. arsort($studentGrades);
  22.  
  23. foreach ($studentGrades as $student => $grade) {
  24.     if ($grade >= 4.50) {
  25.         printf("%s -> %.2f\n", $student, $grade);
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement