deleriumbg

Roli the Coder

Jun 23rd, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Roli_The_Coder
  6. {
  7.     class Event
  8.     {
  9.         public string ID { get; set; }
  10.         public string Name { get; set; }
  11.         public HashSet<string> Participants { get; set; }
  12.     }
  13.  
  14.     class Program
  15.     {
  16.         static void Main(string[] args)
  17.         {
  18.             string input = Console.ReadLine();
  19.             List<Event> events = new List<Event>();
  20.  
  21.             while (input != "Time for Code")
  22.             {
  23.                 string[] eventInfo = input.Split(' ');
  24.                 if (eventInfo.Length < 2)
  25.                 {
  26.                     input = Console.ReadLine();
  27.                     continue;
  28.                 }
  29.                 Event currentEvent = new Event();
  30.                 currentEvent.ID = eventInfo[0].Trim();
  31.                 if (!eventInfo[1].Trim().StartsWith("#"))
  32.                 {
  33.                     input = Console.ReadLine();
  34.                     continue;
  35.                 }
  36.  
  37.                 currentEvent.Name = eventInfo[1].Trim().TrimStart('#');
  38.                 HashSet<string> currentParticipants = new HashSet<string>();
  39.                 currentParticipants.UnionWith(eventInfo.Skip(2));
  40.                 currentEvent.Participants = currentParticipants;
  41.  
  42.                 if (events.All(x => x.ID != currentEvent.ID))
  43.                 {
  44.                     events.Add(currentEvent);
  45.                 }
  46.                 else
  47.                 {
  48.                     if (events.Any(x => x.ID == currentEvent.ID && events.All(y => y.Name != currentEvent.Name)))
  49.                     {
  50.                         input = Console.ReadLine();
  51.                         continue;
  52.                     }
  53.                     if (events.Any(x => x.ID == currentEvent.ID && x.Name == currentEvent.Name))
  54.                     {
  55.                         Event existingEvent = events.First(x => x.ID == currentEvent.ID && x.Name == currentEvent.Name);
  56.                         existingEvent.Participants.UnionWith(currentEvent.Participants);
  57.                     }
  58.                 }
  59.  
  60.                
  61.                 input = Console.ReadLine();
  62.             }
  63.  
  64.             foreach (var eventName in events.OrderByDescending(x => x.Participants.Count).ThenBy(x => x.Name))
  65.             {
  66.                 Console.WriteLine($"{eventName.Name} - {eventName.Participants.Count}");
  67.                 foreach (var participant in eventName.Participants.OrderBy(x => x))
  68.                 {
  69.                     Console.WriteLine($"{participant}");
  70.                 }
  71.             }
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment