Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $coursesStudents = [];
- $input = readline();
- while ($input !== 'end') {
- $cmd = explode(' : ', $input);
- $courseName = $cmd[0];
- $studentName = $cmd[1];
- if (!key_exists($courseName, $coursesStudents)) {
- $coursesStudents[$courseName] = [];
- }
- $coursesStudents[$courseName][] = $studentName;
- $input = readline();
- }
- uksort($coursesStudents, function ($key1, $key2) use ($coursesStudents) {
- $countCourses1 = count($coursesStudents[$key1]);
- $countCourses2 = count($coursesStudents[$key2]);
- return $countCourses2 <=> $countCourses1;
- });
- foreach ($coursesStudents as $course => $students) {
- asort($coursesStudents[$course]);
- echo $course . ": " . count($coursesStudents[$course]) . PHP_EOL;
- foreach ($coursesStudents[$course] as $student) {
- echo "-- $student" . PHP_EOL;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement