Advertisement
Guest User

Untitled

a guest
Mar 7th, 2020
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace _09.ForceBook
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.  
  11.             Dictionary<string, int> sideCounts = new Dictionary<string, int>();
  12.             Dictionary<string, string> sideUsers = new Dictionary<string, string>();
  13.  
  14.             while (true)
  15.             {
  16.                 string input = Console.ReadLine();
  17.  
  18.                 if (input == "Lumpawaroo")
  19.                 {
  20.                     break;
  21.                 }
  22.  
  23.  
  24.  
  25.                 if (input.Contains("|"))
  26.                 {
  27.                     string[] command = input.Split(new string[] { " | ", " -> " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  28.                     string side = command[0];
  29.                     string user = command[1];
  30.  
  31.                     if (!sideUsers.ContainsKey(user))
  32.                     {
  33.                         sideUsers.Add(user, side);
  34.                         sideCounts.Add(side, 0);
  35.  
  36.                         sideCounts[side]++;
  37.                     }
  38.                 }
  39.  
  40.                 else if (input.Contains("->"))
  41.                 {
  42.                     string[] command = input.Split(new string[] { " | ", " -> " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  43.                     string side = command[1];
  44.                     string user = command[0];
  45.  
  46.                     if (sideUsers.ContainsKey(user))
  47.                     {
  48.                         string oldSide = sideUsers[user];
  49.  
  50.                         sideUsers[user] = side;
  51.  
  52.                         sideCounts[oldSide]--;
  53.                         sideCounts[side]++;
  54.                     }
  55.  
  56.                     else
  57.                     {
  58.                         sideUsers.Add(user, side);
  59.  
  60.                         if (sideCounts.ContainsKey(side))
  61.                         {
  62.                             sideCounts[side]++;
  63.                         }
  64.  
  65.                         else
  66.                         {
  67.                             sideCounts.Add(side, 0);
  68.                             sideCounts[side]++;
  69.                         }
  70.  
  71.  
  72.                     }
  73.                     Console.WriteLine($"{user} joins the {side} side!");
  74.                 }
  75.             }
  76.  
  77.            
  78.  
  79.             foreach (var count in sideCounts.Where(x=>x.Value>0).OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  80.             {
  81.  
  82.                 Console.WriteLine($"Side: {count.Key}, Members: {count.Value}");
  83.  
  84.                 foreach (var user in sideUsers.OrderBy(y => y.Key))
  85.                 {
  86.                     if (count.Key == user.Value)
  87.                     {
  88.                         Console.WriteLine($"! {user.Key}");
  89.                     }                  
  90.  
  91.                 }
  92.             }
  93.  
  94.         }
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement