Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace HomeTesting
- {
- public class University
- {
- public static void Main()
- {
- string[] command = Console.ReadLine().Split(':');
- string course = command[0];
- var courseInformation = new Dictionary<string, List<string>>();
- while (course != "end")
- {
- var student = command[1];
- if (!courseInformation.ContainsKey(course))
- {
- courseInformation.Add(course, new List<string> { student });
- }
- else
- {
- courseInformation[course].Add(student);
- }
- command = Console.ReadLine().Split(':');
- course = command[0];
- }
- var sortedInfo = courseInformation
- .OrderByDescending(p => p.Value.Count)
- .ToDictionary(
- p => p.Key,
- p => (IList<string>)p.Value.OrderBy(n => n).ToList()
- );
- foreach (var pair in sortedInfo)
- {
- Console.WriteLine($"{pair.Key.Trim()}: {pair.Value.Count}");
- Console.WriteLine($"--{String.Join(" ", pair.Value)}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement