Teo_Yanchev

Dictionaries - 08. CompanyUsers - C# Fundamentals

Oct 4th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _08._CompanyUsers
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. Dictionary<string, List<string>> employeesBook = new Dictionary<string, List<string>>();
  12.  
  13. string command = Console.ReadLine();
  14. while (command != "End")
  15. {
  16. string[] currentCommand = command.Split(" -> ");
  17.  
  18. string company = currentCommand[0];
  19. string employe = currentCommand[1];
  20.  
  21. if (!employeesBook.ContainsKey(company))
  22. {
  23. employeesBook[company] = new List<string>();
  24. }
  25.  
  26. if (employeesBook[company].Contains(employe))
  27. {
  28. command = Console.ReadLine();
  29. continue;
  30. }
  31.  
  32. employeesBook[company].Add(employe);
  33.  
  34.  
  35. command = Console.ReadLine();
  36. }
  37.  
  38. employeesBook = employeesBook
  39. .OrderBy(x => x.Key)
  40. .ToDictionary(x => x.Key, x => x.Value);
  41.  
  42. foreach (var employee in employeesBook)
  43. {
  44. string company = employee.Key;
  45. List<string> employees = employee.Value;
  46.  
  47. Console.WriteLine($"{company}");
  48.  
  49. foreach (var idNumber in employees)
  50. {
  51. Console.WriteLine($"-- {idNumber}");
  52. }
  53. }
  54. }
  55. }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment