Advertisement
countDecko

Untitled

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