Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace HomeTesting
  6. {
  7. public class University
  8. {
  9. public static void Main()
  10. {
  11. string[] command = Console.ReadLine().Split(':');
  12. string course = command[0];
  13.  
  14. var courseInformation = new Dictionary<string, List<string>>();
  15.  
  16. while (course != "end")
  17. {
  18. var student = command[1];
  19.  
  20. if (!courseInformation.ContainsKey(course))
  21. {
  22. courseInformation.Add(course, new List<string> { student });
  23. }
  24. else
  25. {
  26. courseInformation[course].Add(student);
  27. }
  28.  
  29. command = Console.ReadLine().Split(':');
  30. course = command[0];
  31. }
  32.  
  33. var sortedInfo = courseInformation
  34. .OrderByDescending(p => p.Value.Count)
  35. .ToDictionary(
  36. p => p.Key,
  37. p => (IList<string>)p.Value.OrderBy(n => n).ToList()
  38. );
  39.  
  40. foreach (var pair in sortedInfo)
  41. {
  42. Console.WriteLine($"{pair.Key.Trim()}: {pair.Value.Count}");
  43. Console.WriteLine($"--{String.Join(" ", pair.Value)}");
  44. }
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement