Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $n = intval(readline());
- $studentGrades = [];
- for ($i = 0; $i < 2 * $n; $i++) {
- $input[] = readline();
- if ($i === 0 || $i % 2 === 0) {
- if (!key_exists($input[$i], $studentGrades)) {
- $studentGrades[$input[$i]] = [];
- }
- } else {
- array_push($studentGrades[$input[$i - 1]], floatval($input[$i]));
- }
- }
- foreach ($studentGrades as $student => $grade) {
- $studentGrades[$student] = array_sum($studentGrades[$student]) / count($studentGrades[$student]);
- }
- arsort($studentGrades);
- foreach ($studentGrades as $student => $grade) {
- if ($grade >= 4.50) {
- printf("%s -> %.2f\n", $student, $grade);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement