Advertisement
desislava_topuzakova

04

Mar 31st, 2024
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class Program
  5. {
  6. static void Main()
  7. {
  8. Dictionary<string, List<string>> courses = new Dictionary<string, List<string>>();
  9.  
  10. while (true)
  11. {
  12. string input = Console.ReadLine();
  13.  
  14. if (input == "end")
  15. break;
  16.  
  17. string[] inputParts = input.Split(" : ");
  18. string courseName = inputParts[0];
  19. string studentName = inputParts[1];
  20.  
  21. if (!courses.ContainsKey(courseName))
  22. {
  23. courses.Add(courseName, new List<string>());
  24. }
  25.  
  26. courses[courseName].Add(studentName);
  27. }
  28.  
  29. foreach (var course in courses)
  30. {
  31. Console.WriteLine($"{course.Key}: {course.Value.Count}");
  32. foreach (var student in course.Value)
  33. {
  34. Console.WriteLine($"-- {student}");
  35. }
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement