Advertisement
valkata

roliCoder2

Aug 18th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace rolicoder
  9. {
  10.     class Program
  11.     {
  12.         class Event
  13.         {
  14.             public string Name { get; set; }
  15.             public List<string> Participants { get; set; }
  16.  
  17.             public Event(string name, List<string> participants)
  18.             {
  19.                 Name = name;
  20.                 Participants = participants;
  21.             }
  22.         }
  23.         static void Main(string[] args)
  24.         {
  25.             Dictionary<long, Event> events = new Dictionary<long, Event>();
  26.             string input = Console.ReadLine();
  27.             string pattern = @"^(?<id>[\d]+) #(?<name>[\w]+)(?<participants>[ ?@\w]*)$";
  28.             while (input != "Time for Code")
  29.             {
  30.                 Match currMatch = Regex.Match(input, pattern);
  31.                 long id = long.Parse(currMatch.Groups["id"].Value);
  32.                 string eventName = currMatch.Groups["name"].Value;
  33.                 List<string> participants = new List<string>(currMatch.Groups["participants"].Value
  34.                     .Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)
  35.                     .ToList());
  36.                 if (!events.ContainsKey(id))
  37.                 {
  38.                     events.Add(id, new Event(eventName, participants));
  39.                 }
  40.                 else
  41.                 {
  42.                     if (events[id].Name == eventName)
  43.                     {
  44.                         for (int i = 0; i < participants.Count; i++)
  45.                         {
  46.                             if (!events[id].Participants.Contains(participants[i]))
  47.                             {
  48.                                 events[id].Participants.Add(participants[i]);
  49.                             }
  50.                         }
  51.                     }
  52.                 }
  53.                 input = Console.ReadLine();
  54.             }
  55.  
  56.             var orderedEvents = events
  57.                 .OrderByDescending(oe => oe.Value.Participants.Count())
  58.                 .ThenBy(oe => oe.Value.Name);
  59.  
  60.             foreach (var orderedEvent in orderedEvents)
  61.             {
  62.                 Console.WriteLine("{0} - {1}", orderedEvent.Value.Name, orderedEvent.Value.Participants.Count());
  63.                 foreach (var participant in orderedEvent.Value.Participants.OrderBy(oe => oe))
  64.                 {
  65.                     Console.WriteLine(participant);
  66.                 }
  67.             }
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement