Advertisement
KKK99

08.CompanyUsers

Nov 15th, 2019
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace CompanyUsers
  6. {
  7.     using System;
  8.     using System.Collections.Generic;
  9.     using System.Linq;
  10.  
  11.     class Program
  12.     {
  13.         static void Main()
  14.         {
  15.             Dictionary<string, List<string>> companies = new Dictionary<string, List<string>>();
  16.  
  17.             string inputLine = Console.ReadLine();
  18.  
  19.             while (inputLine != "End")
  20.             {
  21.                 string[] inputArray = inputLine.Split(" -> ");
  22.                 string companyName = inputArray[0];
  23.                 string employeeID = inputArray[1];
  24.  
  25.                 if (!companies.ContainsKey(companyName))
  26.                 {
  27.                     companies.Add(companyName, new List<string>());
  28.                 }
  29.  
  30.                 if (!companies[companyName].Contains(employeeID))
  31.                 {
  32.                     companies[companyName].Add(employeeID);
  33.                 }
  34.  
  35.                 inputLine = Console.ReadLine();
  36.             }
  37.  
  38.  
  39.             foreach (var kvp in companies.OrderBy(kvp => kvp.Key))
  40.             {
  41.                 Console.WriteLine($"{kvp.Key}");
  42.  
  43.                 foreach (var employeeID in kvp.Value)
  44.                 {
  45.                     Console.WriteLine($"-- {employeeID}");
  46.                 }
  47.             }
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement