Advertisement
kmer

Untitled

Mar 9th, 2020
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Courses
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. Dictionary<string, List<string>> allCourses = new Dictionary<string, List<string>>();
  11. while (true)
  12. {
  13. string[] command = Console.ReadLine().Split(" : ");
  14. if (command[0] == "end")
  15. {
  16. break;
  17. }
  18.  
  19. string course = command[0];
  20. string nameStudent = command[1];
  21.  
  22. if (!allCourses.ContainsKey(course))
  23. {
  24. List<string> a = new List<string>();
  25. a.Add(nameStudent);
  26. allCourses.Add(course, a);
  27. }
  28. else
  29. {
  30. allCourses[course].Add(nameStudent);
  31. }
  32. }
  33.  
  34. int x = 0;
  35. string nameCourse = "";
  36. Dictionary<string, List<string>> second = new Dictionary<string, List<string>>();
  37.  
  38. while (allCourses.Count > 0)
  39. {
  40. foreach (var item in allCourses)
  41. {
  42. if (item.Value.Count > x)
  43. {
  44. x = item.Value.Count;
  45. nameCourse = item.Key;
  46. }
  47. }
  48. x = 0;
  49. allCourses[nameCourse].Sort();
  50. second.Add(nameCourse, allCourses[nameCourse]);
  51. allCourses.Remove(nameCourse);
  52. }
  53.  
  54. foreach (var item in second)
  55. {
  56. Console.WriteLine(item.Key + ": " + item.Value.Count);
  57. foreach (var item2 in item.Value)
  58. {
  59. Console.WriteLine("-- " + item2);
  60. }
  61. }
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement