Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _09.ForceBook
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, int> sideCounts = new Dictionary<string, int>();
- Dictionary<string, string> sideUsers = new Dictionary<string, string>();
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "Lumpawaroo")
- {
- break;
- }
- if (input.Contains("|"))
- {
- string[] command = input.Split(new string[] { " | ", " -> " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- string side = command[0];
- string user = command[1];
- if (!sideUsers.ContainsKey(user))
- {
- sideUsers.Add(user, side);
- sideCounts.Add(side, 0);
- sideCounts[side]++;
- }
- }
- else if (input.Contains("->"))
- {
- string[] command = input.Split(new string[] { " | ", " -> " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- string side = command[1];
- string user = command[0];
- if (sideUsers.ContainsKey(user))
- {
- string oldSide = sideUsers[user];
- sideUsers[user] = side;
- sideCounts[oldSide]--;
- sideCounts[side]++;
- }
- else
- {
- sideUsers.Add(user, side);
- if (sideCounts.ContainsKey(side))
- {
- sideCounts[side]++;
- }
- else
- {
- sideCounts.Add(side, 0);
- sideCounts[side]++;
- }
- }
- Console.WriteLine($"{user} joins the {side} side!");
- }
- }
- foreach (var count in sideCounts.Where(x=>x.Value>0).OrderByDescending(x => x.Value).ThenBy(x => x.Key))
- {
- Console.WriteLine($"Side: {count.Key}, Members: {count.Value}");
- foreach (var user in sideUsers.OrderBy(y => y.Key))
- {
- if (count.Key == user.Value)
- {
- Console.WriteLine($"! {user.Key}");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement