Rosen_Tenev

Courses

Mar 20th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Courses
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string command = string.Empty;
  12. var courseInfo = new Dictionary<string, List<string>>();
  13.  
  14.  
  15. while((command=Console.ReadLine())!="end")
  16. {
  17. string[] input = command.Split(":").ToArray();
  18.  
  19. string nameCourse = input[0];
  20. string nameStudent = input[1];
  21. if(!courseInfo.ContainsKey(nameCourse))
  22. {
  23. courseInfo.Add(nameCourse, new List<string>());
  24. courseInfo[nameCourse].Add(nameStudent);
  25. }
  26. else
  27. {
  28. courseInfo[nameCourse].Add(nameStudent);
  29.  
  30. }
  31. }
  32.  
  33.  
  34. foreach (var kvp in courseInfo.OrderByDescending(x=>x.Value.Count))
  35. {
  36. Console.WriteLine($"{kvp.Key}: {kvp.Value.Count}");
  37. foreach (var item in kvp.Value.OrderBy(x => x))
  38. {
  39. Console.WriteLine($"--{item}");
  40. }
  41. }
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment