Advertisement
petyaminkova91

Untitled

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