Advertisement
WindFell

Roli The Coder

Jun 27th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class RoliTheCoder
  6. {
  7.     static void Main(string[] args)
  8.     {
  9.         string request;
  10.  
  11.         var events = new Dictionary<int, Event>();
  12.  
  13.         while ((request = Console.ReadLine()) != "Time for Code")
  14.         {
  15.             if (request.Contains("#") == false)
  16.             {
  17.                 continue;
  18.             }
  19.  
  20.             List<string> tokens = request
  21.                 .Split(" #".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
  22.                 .ToList();
  23.             int id = int.Parse(tokens[0]);
  24.             string name = tokens[1];
  25.             List<string> participants = tokens.Skip(2).ToList();
  26.  
  27.             Event currentEvent = new Event(name, participants);
  28.  
  29.             if (events.ContainsKey(id) == false)
  30.             {
  31.                 events.Add(id, currentEvent);
  32.             }
  33.             else if(events[id].Name == name)
  34.             {
  35.                 events[id].Participants.AddRange(currentEvent.Participants);
  36.             }
  37.  
  38.             events[id].Participants = events[id].Participants.Distinct().ToList();
  39.         }
  40.  
  41.         foreach (Event currentEvent in events.Values.OrderByDescending(e => e.Participants.Count).ThenBy(e => e.Name))
  42.         {
  43.             Console.WriteLine($"{currentEvent.Name} - {currentEvent.Participants.Count}");
  44.  
  45.             foreach (string participant in currentEvent.Participants.OrderBy(p => p))
  46.             {
  47.                 Console.WriteLine(participant);
  48.             }
  49.         }
  50.     }
  51. }
  52.  
  53. class Event
  54. {
  55.     public Event(string name, List<string> participants)
  56.     {
  57.         this.Name = name;
  58.         this.Participants = participants;
  59.     }
  60.  
  61.     public string Name { get; set; }
  62.     public List<string> Participants { get; set; }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement