Advertisement
shady_obeyd

04.RoliTheCoder

Nov 2nd, 2017
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _04.RoliTheCoder
  6. {
  7.     class RoliTheCoder
  8.     {
  9.         static void Main()
  10.         {
  11.             var data = new Dictionary<string, Dictionary<string, List<string>>>();
  12.  
  13.             string input = Console.ReadLine();
  14.  
  15.             while (input != "Time for Code")
  16.             {
  17.                 string[] tokens = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  18.  
  19.                 string id = tokens[0];
  20.                 string eventt = tokens[1];
  21.  
  22.                 if (eventt.StartsWith("#"))
  23.                 {
  24.                     eventt = eventt.Remove(0, 1);
  25.                     if (!data.ContainsKey(id))
  26.                     {
  27.                         data.Add(id, new Dictionary<string, List<string>>());
  28.  
  29.                         if (!data[id].ContainsKey(eventt))
  30.                         {
  31.                             data[id].Add(eventt, new List<string>());
  32.                             AddParticipants(tokens, data[id][eventt]);
  33.                         }
  34.                     }
  35.  
  36.                     if (data[id].ContainsKey(eventt))
  37.                     {
  38.                         AddParticipants(tokens, data[id][eventt]);
  39.                     }
  40.  
  41.                 }
  42.  
  43.                 input = Console.ReadLine();
  44.             }
  45.  
  46.             foreach (var eventData in data.OrderByDescending(p => p.Value.Values.Sum(v => v.Count)).ThenBy(n => n.Key))
  47.             {
  48.                 Dictionary<string, List<string>> events = eventData.Value;
  49.  
  50.                 foreach (var item in events)
  51.                 {
  52.                     string eventt = item.Key;
  53.                     List<string> participants = item.Value;
  54.  
  55.                     participants.Sort();
  56.  
  57.                     Console.WriteLine($"{eventt} - {participants.Count}");
  58.  
  59.                     Console.WriteLine(string.Join(Environment.NewLine, participants));
  60.                 }
  61.             }
  62.         }
  63.  
  64.         private static void AddParticipants(string[] tokens, List<string> list)
  65.         {
  66.             for (int i = 2; i < tokens.Length; i++)
  67.             {
  68.  
  69.                 if (!list.Contains(tokens[i]))
  70.                 {
  71.                     list.Add(tokens[i]);
  72.                 }
  73.  
  74.             }
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement