ZhivkoPetkov

RoliTheCoder

Aug 14th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace RoliTheCoder
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             var input = Console.ReadLine();
  15.  
  16.             var eventId = new Dictionary<int, string>();
  17.             var eventParticipands = new Dictionary<string, HashSet<string>>();
  18.  
  19.             while (input != "Time for Code")
  20.             {
  21.                 var info = input.Split(new char[] { ' ' },StringSplitOptions.RemoveEmptyEntries).ToList();
  22.  
  23.                 if (info[1].StartsWith("#"))
  24.                 {
  25.                     var id = int.Parse(info[0]);
  26.                     string eventName = info[1].Substring(1);
  27.                     var participants = info.Skip(2).ToList();
  28.  
  29.                     if (eventId.ContainsKey(id)==false)
  30.                     {
  31.                         eventId.Add(id, eventName);
  32.                         eventParticipands.Add(eventName, new HashSet<string>());
  33.                     }
  34.  
  35.                     if (eventId.ContainsKey(id) && eventId[id]==eventName)
  36.                     {
  37.  
  38.                         foreach (var participand in participants)
  39.                         {
  40.                             eventParticipands[eventName].Add(participand);
  41.                         }
  42.                     }
  43.  
  44.  
  45.                 }
  46.                 input = Console.ReadLine();
  47.             }
  48.  
  49.             foreach (var eventName in eventParticipands.OrderByDescending(x=>x.Value.Count()).ThenBy(x=>x.Key))
  50.             {
  51.                 Console.WriteLine($"{eventName.Key} - {eventName.Value.Count()}");
  52.  
  53.                 foreach (var item in eventName.Value.OrderBy(x=>x))
  54.                 {
  55.                     Console.WriteLine(item);
  56.                 }
  57.                
  58.             }
  59.  
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment