Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2017
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ExamPreparation
  7. {
  8.     public class Event
  9.     {
  10.         public Event(string name)
  11.         {
  12.             this.Name = name;
  13.             this.Participants = new SortedSet<string>();
  14.         }
  15.  
  16.         public string Name { get; private set; }
  17.  
  18.         public SortedSet<string> Participants { get; set; }
  19.  
  20.         public override string ToString()
  21.         {
  22.             StringBuilder output = new StringBuilder();
  23.  
  24.             output.AppendLine($"{this.Name} - {this.Participants.Count}");
  25.  
  26.             foreach (var participant in this.Participants)
  27.             {
  28.                 output.AppendLine(participant);
  29.             }
  30.  
  31.             return output.ToString().Trim();
  32.         }
  33.     }
  34.  
  35.     class Startup
  36.     {
  37.         static void Main()
  38.         {
  39.             Dictionary<string, Event> events = new Dictionary<string, Event>();
  40.             string input = Console.ReadLine();
  41.  
  42.             while (input != "Time for Code")
  43.             {
  44.                 string[] tokens = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  45.                 string id = tokens[0];
  46.                 string eventName = tokens[1];
  47.                 string clearedName = eventName.Substring(1);
  48.  
  49.                 if (eventName.Contains("#"))
  50.                 {
  51.                     if (!events.ContainsKey(id))
  52.                     {
  53.                         events.Add(id, new Event(clearedName));
  54.                         AddNewParticipants(tokens, events, id);
  55.                     }
  56.                     else
  57.                     {
  58.                         if (events[id].Name == clearedName)
  59.                         {
  60.                             AddNewParticipants(tokens, events, id);
  61.                         }
  62.                     }
  63.                 }
  64.  
  65.                 input = Console.ReadLine();
  66.             }
  67.  
  68.             foreach (var @event in events.OrderByDescending(e => e.Value.Participants.Count).ThenBy(e => e.Value.Name))
  69.             {
  70.                 Console.WriteLine(@event.Value);
  71.             }
  72.         }
  73.  
  74.         private static void AddNewParticipants(string[] tokens, Dictionary<string, Event> events, string id)
  75.         {
  76.             IEnumerable<string> participants = tokens.Skip(2);
  77.  
  78.             foreach (var participant in participants)
  79.             {
  80.                 events[id].Participants.Add(participant);
  81.             }
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement