Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Courses
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] input = Console.ReadLine().Split(" : ");
- Dictionary<string, List<string>> dictOfStudents = new Dictionary<string, List<string>>();
- while (input[0] != "end")
- {
- string courseName = input[0];
- string studentName = input[1];
- AddCourseOrStudent(dictOfStudents, courseName, studentName);
- input = Console.ReadLine().Split(" : ");
- }
- foreach (var item in dictOfStudents.OrderByDescending(x => x.Value.Count))
- {
- Console.WriteLine($"{item.Key}: {item.Value.Count}");
- foreach (var name in dictOfStudents[item.Key].OrderBy(x => x))
- {
- Console.WriteLine("-- " + name);
- }
- }
- }
- static Dictionary<string, List<string>> AddCourseOrStudent(Dictionary<string, List<string>> dict, string course, string student)
- {
- if (dict.ContainsKey(course))
- {
- dict[course].Add(student);
- }
- else
- {
- dict.Add(course, new List<string>() { student });
- }
- return dict;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement