Advertisement
Spocoman

07. Company Users

Apr 8th, 2023
1,141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace CompanyUsers
  6. {
  7.     class Program
  8.     {
  9.         public static void Main()
  10.         {
  11.             Dictionary<string, List<string>> companies = new Dictionary<string, List<string>>();
  12.  
  13.             string command;
  14.  
  15.             while ((command = Console.ReadLine()) != "End")
  16.             {
  17.                 string[] current = command.Split(" -> ");
  18.  
  19.                 string company = current[0];
  20.                 string employeeID = current[1];
  21.  
  22.                 if (!companies.ContainsKey(company))
  23.                 {
  24.                     companies.Add(company, new List<string>());
  25.                 }
  26.  
  27.                 if (!companies[company].Contains(employeeID))
  28.                 {
  29.                     companies[company].Add(employeeID);
  30.                 }
  31.             }
  32.  
  33.             foreach (var company in companies)
  34.             {
  35.                 Console.WriteLine($"{company.Key}\n-- {string.Join("\n-- ", company.Value)}");
  36.             }
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement