StoimenK

C# 2.8.Company_Users

Mar 13th, 2020
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace _2._8.Company_Users
  5. {
  6.     class Program
  7.     {
  8.         static void Main()
  9.         {
  10.             SortedDictionary<string, List<string>> companies = new SortedDictionary<string, List<string>>();
  11.  
  12.  
  13.             while (true)
  14.             {
  15.                 string[] commnad = Console.ReadLine().Split(new char[] { ' ', '-', '>' }, StringSplitOptions.RemoveEmptyEntries);
  16.  
  17.                 if (commnad[0] == "End")
  18.                 {
  19.                     break;
  20.                 }
  21.  
  22.                 if (!companies.ContainsKey(commnad[0]))
  23.                 {
  24.                     companies.Add(commnad[0], new List<string>() { commnad[1] });
  25.                 }
  26.                 else
  27.                 {
  28.                     if (!companies[commnad[0]].Contains(commnad[1]))
  29.                     {
  30.                         companies[commnad[0]].Add(commnad[1]);
  31.                     }
  32.                 }
  33.             }
  34.  
  35.             foreach (var kvp in companies)
  36.             {
  37.                 Console.WriteLine($"{kvp.Key}");
  38.  
  39.                 foreach (var id in kvp.Value)
  40.                 {
  41.                     Console.WriteLine($"-- {id}");
  42.                 }
  43.             }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment