Advertisement
Danny_Berova

04.RoliTheCoder

Aug 14th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.32 KB | None | 0 0
  1.  
  2. namespace _04.RoliTheCoder
  3. {
  4.     using System;
  5.     using System.Collections.Generic;
  6.     using System.Linq;
  7.  
  8.     public class Event
  9.     {
  10.         public string Name { get; set; }
  11.  
  12.         public long Id { get; set; }
  13.  
  14.         public List<string> Participants { get; set; }
  15.     }
  16.  
  17.     public class Program
  18.     {
  19.         public static void Main()
  20.         {
  21.             Dictionary<long, Event> eventsById = new Dictionary<long, Event>();
  22.  
  23.             while (true)
  24.             {
  25.                 string inputLine = Console.ReadLine();
  26.  
  27.                 if (inputLine == "Time for Code")
  28.                 {
  29.                     break;
  30.                 }
  31.  
  32.                 string[] tokens = inputLine.Split(new[] { ' ' },
  33.                     StringSplitOptions.RemoveEmptyEntries);
  34.  
  35.                 long id = 0;
  36.  
  37.                 if (!long.TryParse(tokens[0], out id))
  38.                 {
  39.                     continue;
  40.                 }
  41.  
  42.                 id = long.Parse(tokens[0]);
  43.  
  44.                 string eventName = null;
  45.                 if (tokens.Length > 1 && tokens[1].StartsWith("#"))
  46.                 {
  47.                     eventName = tokens[1].TrimStart('#');
  48.                 }
  49.                 else
  50.                 {
  51.                     continue;
  52.                 }
  53.  
  54.                 var participantsToAdd = new List<string>();
  55.                 if (tokens.Length > 2)
  56.                 {
  57.                     participantsToAdd = tokens.Skip(2).ToList();
  58.  
  59.                     if (!participantsToAdd.All(p => p.StartsWith("@")))
  60.                     {
  61.                         continue;
  62.                     }
  63.                 }
  64.  
  65.                 Event newEvent = new Event
  66.                 {
  67.                     Name = eventName,
  68.                     Id = id,
  69.                     Participants = new List<string>()
  70.                 };
  71.  
  72.                 if (!eventsById.ContainsKey(id))
  73.                 {
  74.                     eventsById[id] = newEvent;
  75.                 }
  76.                
  77.                 if (eventsById.ContainsKey(id))
  78.                 {
  79.                     if (eventsById[id].Id != id && eventsById[id].Name == eventName)
  80.                     {
  81.                         continue;
  82.                     }
  83.                     else if (eventsById[id].Id == id && eventsById[id].Name == eventName)
  84.                     {
  85.                         for (int i = 0; i < participantsToAdd.Count; i++)
  86.                         {
  87.                             if (!eventsById[id].Participants.Contains(participantsToAdd[i]))
  88.                             {
  89.                                 eventsById[id].Participants.Add(participantsToAdd[i]);
  90.                             }
  91.                         }
  92.                     }
  93.                 }
  94.             }
  95.  
  96.             foreach (var eventEntry in eventsById
  97.                 .OrderByDescending(id => id.Value.Participants.Count)
  98.                 .ThenBy(id => id.Value.Name)
  99.                 .ThenBy(id => id.Value.Participants))
  100.             {
  101.                 Event ev = eventEntry.Value;
  102.                 Console.WriteLine($"{ev.Name} - {ev.Participants.Count}");
  103.  
  104.                 foreach (var participant in eventEntry.Value.Participants.OrderBy(x => x))
  105.                 {
  106.                     Console.WriteLine(participant);
  107.                 }
  108.             }
  109.         }
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement