Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace _3.RoliTheCoder
- {
- class Program
- {
- static void Main(string[] args)
- {
- var dict = new Dictionary<int, Dictionary<string, List<string>>>();
- while (true)
- {
- string command = Console.ReadLine();
- if (command == "Time for Code")
- {
- break;
- }
- if (IsValid(command) == false)
- {
- continue;
- }
- string[] tokens = command.Split().ToArray();
- int id = int.Parse(tokens[0]);
- string eventName = tokens[1].TrimStart('#');
- if (tokens.Length <= 2)
- {
- if (!dict.ContainsKey(id))
- {
- List<string> insideList = new List<string>();
- var insideDict = new Dictionary<string, List<string>>();
- insideDict.Add(eventName, insideList);
- dict.Add(id, insideDict);
- continue;
- }
- }
- List<string> inner = new List<string>();
- for (int i = 2; i < tokens.Length; i++)
- {
- inner.Add(tokens[i]);
- }
- var innerList = inner.Distinct().ToList();
- if (!dict.ContainsKey(id))
- {
- var insideDict = new Dictionary<string, List<string>>();
- insideDict.Add(eventName, innerList);
- dict.Add(id, insideDict);
- }
- else
- {
- if (dict[id].ContainsKey(eventName))
- {
- for (int i = 0; i < innerList.Count; i++)
- {
- if (!dict[id][eventName].Contains(innerList[i]))
- {
- dict[id][eventName].Add(innerList[i]);
- }
- }
- }
- }
- }
- foreach (var item in dict.OrderByDescending(x => dict[x.Key].Values.First().Count).ThenBy(y => dict[y.Key].Values.First()))
- {
- foreach (var party in item.Value.OrderBy(x => x))
- {
- Console.WriteLine($"{party.Key} - {party.Value.Count}");
- foreach (var person in party.Value.OrderBy(x => x))
- {
- Console.WriteLine($"{person}");
- }
- }
- }
- }
- static bool IsValid(string command)
- {
- string pattern = @"([0-9]+) (#[A-Za-z0-9]+)( (@[A-Za-z]+))*";
- var match = Regex.Match(command, pattern);
- if (match.Success)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment