TheBulgarianWolf

SoftUni Courses

Mar 3rd, 2021
873
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace CoursesSoftUni
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string input;
  11.             Dictionary<string, List<string>> courses = new Dictionary<string, List<string>>();
  12.             while((input = Console.ReadLine()) != "end")
  13.             {
  14.                 string[] inputArr = input.Split(" : ");
  15.                 if (courses.ContainsKey(inputArr[0]))
  16.                 {
  17.                     courses[inputArr[0]].Add(inputArr[1]);
  18.                 }
  19.                 else
  20.                 {
  21.                     courses.Add(inputArr[0], new List<string>());
  22.                     courses[inputArr[0]].Add(inputArr[1]);
  23.                 }
  24.             }
  25.  
  26.             foreach(var item in courses)
  27.             {
  28.                 Console.WriteLine(item.Key + ": " + item.Value.Count);
  29.                 foreach(var participant in item.Value)
  30.                 {
  31.                     Console.WriteLine("-- "+participant);
  32.                 }
  33.             }
  34.         }
  35.     }
  36. }
  37.  
Add Comment
Please, Sign In to add comment