Advertisement
mastersan12

Companu Users

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