Teo_Yanchev

06. Courses - C# Fundamentals

Oct 4th, 2020
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _06._Courses
  6. {
  7. class Courses
  8. {
  9. static void Main()
  10. {
  11. Dictionary<string, List<string>> dictCourses = new Dictionary<string, List<string>>();
  12.  
  13.  
  14. string command = Console.ReadLine();
  15. while (command != "end")
  16. {
  17. string[] currentCommand = command.Split(" : ").ToArray();
  18.  
  19. string courseName = currentCommand[0];
  20. string studnetName = currentCommand[1];
  21.  
  22. if (!dictCourses.ContainsKey(courseName))
  23. {
  24. dictCourses[courseName] = new List<string>();
  25.  
  26. dictCourses[courseName].Add(studnetName);
  27. }
  28. else
  29. {
  30. dictCourses[courseName].Add(studnetName);
  31. }
  32.  
  33. command = Console.ReadLine();
  34. }
  35.  
  36. dictCourses = dictCourses
  37. .OrderByDescending(x => x.Value.Count())
  38. .ToDictionary(x => x.Key, x => x.Value);
  39.  
  40.  
  41. foreach (var student in dictCourses)
  42. {
  43. Console.WriteLine($"{student.Key}: {student.Value.Count()}");
  44.  
  45. student.Value.Sort();
  46.  
  47. for (int i = 0; i < 1; i++)
  48. {
  49. Console.WriteLine($"-- {string.Join("\n-- ", student.Value)}");
  50. }
  51.  
  52. }
  53.  
  54. }
  55. }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment