Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace RollTheCoder
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string command = Console.ReadLine();
  13.  
  14.             Dictionary<string, Event> events = new Dictionary<string, Event>();
  15.  
  16.             while (!command.Equals("Time for Code"))
  17.             {
  18.                 string pattern = @"[0-9a-zA-Z]+\s+#[0-9a-zA-Z]+\s*(@[a-zA-Z]+\s*)*";
  19.                 Regex regex = new Regex(pattern);
  20.  
  21.                 if (regex.IsMatch(command))
  22.                 {
  23.                     string[] commandLine = command
  24.                                   .Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
  25.                     string id = commandLine[0];
  26.                     string eventName = commandLine[1];
  27.  
  28.                     List<string> participants = new List<string>();
  29.  
  30.                     for (int i = 2; i < commandLine.Length; i++)
  31.                     {
  32.  
  33.                         participants.Add(commandLine[i].Substring(1));
  34.                     }
  35.  
  36.                     Event roliEvent = new Event();
  37.  
  38.                     roliEvent.id = id;
  39.                     roliEvent.name = eventName;
  40.                     roliEvent.participants = participants;
  41.  
  42.                     List<string> part = new List<string>();
  43.                     part = roliEvent.participants.Distinct().ToList();
  44.  
  45.                     roliEvent.participants = part;
  46.  
  47.                     if (!events.ContainsKey(id))
  48.                     {
  49.                         events.Add(id, roliEvent);
  50.                     }
  51.                     else
  52.                     {
  53.                         if (events[id].name == roliEvent.name)
  54.                         {
  55.                             events[id].participants.AddRange(participants);
  56.  
  57.                             List<string> distinctPart = new List<string>();
  58.                             distinctPart = events[id].participants.Distinct().ToList();
  59.  
  60.                             events[id].participants = distinctPart;
  61.  
  62.                         }
  63.                     }
  64.                 }
  65.  
  66.                 command = Console.ReadLine();
  67.             }
  68.  
  69.             foreach (var roliEvent in events.OrderByDescending(x => x.Value.participants.Count).ThenBy(x => x.Value.name))
  70.             {
  71.                
  72.                 Console.WriteLine("{0} - {1}", roliEvent.Value.name.Substring(1), roliEvent.Value.participants.Count);
  73.  
  74.                 roliEvent.Value.participants.Sort();
  75.  
  76.                 foreach (var participant in roliEvent.Value.participants)
  77.                 {
  78.                     Console.WriteLine($"@{participant}");
  79.                 }
  80.             }
  81.         }
  82.     }
  83.  
  84.  
  85.     public class Event
  86.     {
  87.         public string id { get; set; }
  88.         public string name { get; set; }
  89.         public List<string> participants { get; set; }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement