Advertisement
Simeon1995

Untitled

Nov 4th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Roli_the_Coder_second_try
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Dictionary<int, List<string>> eventNamesParticipants = new Dictionary<int, List<string>>();
  14.             while (true)
  15.             {
  16.                 List<string> input = Console.ReadLine().Split(' ').Select(data => data.Trim()).ToList();
  17.                 if (input[0] == "Time")
  18.                     break;
  19.                 if (CheckValidity(input))
  20.                     continue;
  21.                 int id = int.Parse(input[0]);
  22.                 string eventName = input[1].Substring(1);
  23.                 if (!eventNamesParticipants.ContainsKey(id))
  24.                 {
  25.                     eventNamesParticipants.Add(id, new List<string>());
  26.                     eventNamesParticipants[id].Add(eventName);
  27.                     for (int i = 2; i < input.Count; i++)
  28.                     {
  29.                         eventNamesParticipants[id].Add(input[i]);
  30.                     }
  31.                     eventNamesParticipants[id] = eventNamesParticipants[id].Distinct().ToList();
  32.                 }
  33.                 if (eventNamesParticipants.ContainsKey(id) && eventNamesParticipants[id][0] == eventName)
  34.                 {
  35.                     for (int i = 2; i < input.Count; i++)
  36.                     {
  37.                         eventNamesParticipants[id].Add(input[i]);
  38.                     }
  39.                     eventNamesParticipants[id] = eventNamesParticipants[id].Distinct().ToList();
  40.                 }
  41.             }
  42.             foreach (var events in eventNamesParticipants.OrderByDescending(participants => participants.Value.Count).ThenBy(events => events.Value[0]))
  43.             {
  44.                 Console.WriteLine($"{events.Value[0]} - {events.Value.Count - 1}");
  45.                 foreach (var participant in events.Value.OrderBy(name => name))
  46.                 {
  47.                     if (!participant.StartsWith("@"))
  48.                         continue;
  49.                     Console.WriteLine(participant);
  50.                 }
  51.             }
  52.         }
  53.         static bool CheckValidity(List<string> input)
  54.         {
  55.             if (!input[1].StartsWith("#"))
  56.                 return true;
  57.             for (int i = 2; i < input.Count; i++)
  58.             {
  59.                 Match match = Regex.Match(input[i], @"^@[a-zA-Z-'0-9]+$");
  60.                 if (!match.Success)
  61.                     return true;
  62.             }
  63.             return false;
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement