Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 11. Courses
- Write a program that keeps information about courses. Each course has a name and registered students.
- You will be receiving a course name and a student name, until you receive the command "end". Check if such course already exists, and if not, add the course. Register the user into the course. When you receive the command "end", print the courses with their names and total registered users, ordered by the count of registered users in descending order. For each contest print the registered users ordered by name in ascending order.
- Input
- • Until the "end" command is received, you will be receiving input in the format: "{courseName} : {studentName}".
- • The product data is always delimited by " : ".
- Output
- • Print the information about each course in the following the format:
- "{courseName}: {registeredStudents}"
- • Print the information about each student, in the following the format:
- "-- {studentName}"
- Examples
- Input Output
- Programming Fundamentals : John Smith Programming Fundamentals: 2
- Programming Fundamentals : Linda Johnson -- John Smith
- JS Core : Will Wilson -- Linda Johnson
- Java Advanced : Harrison White JS Core: 1
- end -- Will Wilson
- Java Advanced: 1
- -- Harrison White
- Algorithms : Jay Moore Python Fundamentals: 3
- Programming Basics : Martin Taylor -- Andrew Robinson
- Python Fundamentals : John Anderson -- Clark Lewis
- Python Fundamentals : Andrew Robinson -- John Anderson
- Algorithms : Bob Jackson Algorithms: 2
- Python Fundamentals : Clark Lewis -- Bob Jackson
- end -- Jay Moore
- Programming Basics: 1
- -- Martin Taylor
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _11Courses
- {
- class Program
- {
- static void Main(string[] args)
- {
- var registered = new Dictionary<string, List<string>>();
- string courseAndStudent;
- while ((courseAndStudent = Console.ReadLine()) != "end")
- {
- var courseSplitted = courseAndStudent.Split(" : ");
- var courseName = courseSplitted[0];
- var studentName = courseSplitted[1];
- if (!registered.ContainsKey(courseName))
- {
- registered.Add(courseName, new List<string>() { studentName });
- }
- else
- {
- registered[courseName].Add(studentName);
- }
- }
- foreach (var course in registered.OrderByDescending(x => x.Value.Count))
- {
- Console.WriteLine($"{course.Key}: {course.Value.Count()}");
- foreach (var name in course.Value.OrderBy(x => x))
- {
- Console.WriteLine($"-- {name}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment