Advertisement
Guest User

Untitled

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