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)
- {
- string input = string.Empty;
- string side = string.Empty;
- string name = string.Empty;
- var sides = new Dictionary<string, List<string>>();
- while ((input = Console.ReadLine()) != "Lumpawaroo")
- {
- if (input.Contains("|"))
- {
- side = input.Split(" | ")[0];
- name = input.Split(" | ")[1];
- if (!sides.ContainsKey(side))
- {
- sides.Add(side, new List<string>());
- sides[side].Add(name);
- }
- else
- {
- if (!sides[side].Contains(name))
- {
- sides[side].Add(name);
- }
- }
- }
- else if (input.Contains("->"))
- {
- side = input.Split(" -> ")[1];
- name = input.Split(" -> ")[0];
- int index = 0;
- foreach (var item in sides)
- {
- if (item.Value.Contains(name))
- {
- index = item.Value.IndexOf(name);
- item.Value.RemoveAt(index);
- break;
- }
- }
- if (sides.ContainsKey(side))
- {
- Console.WriteLine($"{name} joins the {side} side!");
- sides[side].Add(name);
- }
- else
- {
- Console.WriteLine($"{name} joins the {side} side!");
- sides.Add(side, new List<string>());
- sides[side].Add(name);
- }
- }
- }
- sides = sides.OrderByDescending(x => x.Value.Count).ThenBy(x => x.Key).ToDictionary(a => a.Key, b => b.Value);
- foreach (var item in sides)
- {
- if (item.Value.Count == 0)
- {
- continue;
- }
- Console.WriteLine($"Side: {item.Key}, Members: {item.Value.Count}");
- sides[item.Key].Sort();
- foreach (var items in sides[item.Key])
- {
- Console.WriteLine($"! {items}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement