Advertisement
dragonbs

Courses

Mar 7th, 2023
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. internal class Program
  6. {
  7.     static void Main()
  8.     {
  9.         Dictionary<string, List<string>> courses = new Dictionary<string, List<string>>();
  10.         string input;
  11.         while ((input = Console.ReadLine()) != "end")
  12.         {
  13.             string[] commands = input.Split(new string[] { " : " }, StringSplitOptions.None);
  14.             string course = commands[0];
  15.             string student = commands[1];
  16.             if (!courses.ContainsKey(course))
  17.                 courses.Add(course, new List<string>());
  18.             courses[course].Add(student);
  19.         }
  20.  
  21.         foreach (KeyValuePair<string, List<string>> course in courses)
  22.         {
  23.             Console.WriteLine($"{course.Key}: {course.Value.Count}");
  24.             course.Value.ForEach(x => Console.WriteLine($"-- {x}"));
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement