Chessmaster

Untitled

Nov 5th, 2018
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.IO;
  5.  
  6. namespace CompanyUsers
  7. {
  8.     class Program
  9.     {
  10.         public static void Main()
  11.         {
  12.             var usersByCompany = new Dictionary<string, List<string>>();
  13.             //var idsBy = new Dictionary<string,>();
  14.  
  15.             while (true)
  16.             {
  17.                 string[] tokens = Console.ReadLine().Split("-> ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  18.  
  19.                 if (tokens[0] == "End")
  20.                 {
  21.                     break;
  22.                 }
  23.  
  24.                 string companyName = tokens[0];
  25.                 string employeeId = tokens[1];
  26.  
  27.                 if (usersByCompany.ContainsKey(companyName) == false)
  28.                 {
  29.                     usersByCompany.Add(companyName, new List<string>());
  30.                 }
  31.  
  32.                 if (usersByCompany[companyName].Contains(employeeId) == false) // pf... it was that simple...
  33.                 {
  34.                     usersByCompany[companyName].Add(employeeId);
  35.                 }
  36.             }
  37.  
  38.             foreach (var kvp in usersByCompany.OrderBy(c => c.Key))
  39.             {
  40.                 Console.WriteLine(kvp.Key);
  41.                 kvp.Value.ForEach(x => Console.WriteLine("-- {0}", x));
  42.             }
  43.         }
  44.     }
  45. } // . yooooooooooooooooooooooooooo
Advertisement
Add Comment
Please, Sign In to add comment