TheBulgarianWolf

Company Users

Mar 4th, 2021
1,034
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace CompanyUsers
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string input;
  12.             Dictionary<string, List<string>> companies = new Dictionary<string, List<string>>();
  13.             while((input = Console.ReadLine()) != "End")
  14.             {
  15.                 string[] separated = input.Split(" -> ");
  16.                 string compName = separated[0];
  17.                 string id = separated[1];
  18.                 if (companies.ContainsKey(compName))
  19.                 {
  20.                     companies[compName].Add(id);
  21.                 }
  22.                 else
  23.                 {
  24.                     companies.Add(compName, new List<string>());
  25.                     companies[compName].Add(id);
  26.                 }
  27.             }
  28.  
  29.             var ordered = companies.OrderBy(k => k.Key);
  30.             foreach(var item in ordered)
  31.             {
  32.                 Console.WriteLine(item.Key);
  33.                 foreach(var list in item.Value)
  34.                 {
  35.                     Console.WriteLine("--" + list);
  36.                 }
  37.             }
  38.         }
  39.     }
  40. }
  41.  
Add Comment
Please, Sign In to add comment