Advertisement
nikolapetkov824

9.ForceBook

Nov 24th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace RegularExpressions
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Dictionary<string, List<string>> forceSideUsers =
  13.                 new Dictionary<string, List<string>>();
  14.  
  15.  
  16.             while (true)
  17.             {
  18.                 string input = Console.ReadLine();
  19.  
  20.                 if (input=="Lumpawaroo")
  21.                 {
  22.                     break;
  23.                 }
  24.                 else
  25.                 {
  26.                     if (input.Contains("|"))
  27.                     {
  28.                         string[] forceBook = input.Split(" | ");
  29.  
  30.                         string forceSide = forceBook[0];
  31.                         string forceUser = forceBook[1];
  32.  
  33.                         if (!forceSideUsers.ContainsKey(forceSide))
  34.                         {
  35.                             forceSideUsers.Add(forceSide, new List<string>());
  36.                         }
  37.  
  38.                         if (!forceSideUsers[forceSide].Contains(forceUser))
  39.                         {
  40.                             forceSideUsers[forceSide].Add(forceUser);
  41.                         }
  42.                        
  43.                     }
  44.                     else
  45.                     {
  46.                         string[] forceBook = input.Split(" -> ");
  47.  
  48.                         string forceSide = forceBook[1];
  49.                         string forceUser = forceBook[0];
  50.  
  51.                         if (forceSideUsers.ContainsKey(forceSide))
  52.                         {
  53.                             if (!forceSideUsers[forceSide].Contains(forceUser))
  54.                             {
  55.                                 forceSideUsers[forceSide].Add(forceUser);
  56.                                 Console.WriteLine($"{forceUser} joins the {forceSide} side!");
  57.                             }
  58.                             else
  59.                             {
  60.                                 forceSideUsers[forceSide].Remove(forceUser);
  61.                             }
  62.                         }
  63.                     }
  64.  
  65.  
  66.                 }
  67.             }
  68.  
  69.             foreach (var kvp in forceSideUsers)
  70.             {
  71.                 Console.WriteLine($"Side: {kvp.Key}, Members: {kvp.Value.Count}");
  72.  
  73.                 foreach (var user in kvp.Value)
  74.                 {
  75.                     Console.WriteLine($"! {user}");
  76.                 }
  77.             }
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement