Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace P06._Courses
  6. {
  7. class StartUp
  8. {
  9. static void Main()
  10. {
  11. var coursesStudents = new Dictionary<string, List<string>>();
  12.  
  13. while (true)
  14. {
  15. string line = Console.ReadLine();
  16. if (line == "end")
  17. {
  18. break;
  19. }
  20.  
  21. string[] splitedLine = line.Split(" : ");
  22. string course = splitedLine[0];
  23. string name = splitedLine[1];
  24.  
  25. if (!coursesStudents.ContainsKey(course))
  26. {
  27. List<string> students = new List<string>();
  28. students.Add(name);
  29. coursesStudents.Add(course, students);
  30. }
  31. else
  32. {
  33. coursesStudents[course].Add(name);
  34. }
  35. }
  36.  
  37. var dict = coursesStudents.OrderByDescending(x => x.Value.Count);
  38.  
  39. foreach (var kvp in dict)
  40. {
  41. Console.WriteLine($"{kvp.Key}: {kvp.Value.Count}");
  42.  
  43. var orderStudents = kvp.Value.OrderBy(x => x).ToList();
  44. foreach (var student in orderStudents)
  45. {
  46. Console.WriteLine($"-- {student}");
  47. }
  48. }
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement