Advertisement
Guest User

Untitled

a guest
Feb 28th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.03 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.Specialized;
  4. using System.Dynamic;
  5. using System.Linq;
  6. using System.Text.RegularExpressions;
  7.  
  8. namespace _04._Roli_The_Coder
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string input = String.Empty;
  15.             Dictionary<int, string> ID = new Dictionary<int, string>();
  16.             Dictionary<string, List<string>> participant =
  17.                 new Dictionary<string, List<string>>();
  18.             while ((input = Console.ReadLine()) != "Time for Code")
  19.             {
  20.                 string[] tokens = input
  21.                     .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  22.                     .Select(x => x.Trim()).ToArray();
  23.                 int id = int.Parse(tokens[0]);
  24.                 string eventName = tokens[1];
  25.                 if (!eventName.StartsWith("#"))
  26.                 {
  27.                     continue;
  28.                 }
  29.                 string pattern = @"^(@[a-zA-Z0-9'-]+)$";
  30.                 if (!ID.ContainsKey(id))
  31.                 {
  32.                     ID.Add(id, eventName);
  33.                     participant.Add(eventName, new List<string>());
  34.                     for (int i = 2; i < tokens.Length; i++)
  35.                     {
  36.                         Match match = Regex.Match(tokens[i], pattern);
  37.                         if (match.Success)
  38.                         {
  39.                             if (!participant[eventName].Contains(tokens[i]))
  40.                             {
  41.                                 participant[eventName].Add(tokens[i]);
  42.                             }
  43.                         }
  44.                     }
  45.                 }
  46.                 else if (ID.ContainsKey(id))
  47.                 {
  48.                     if (ID[id] == eventName)
  49.                     {
  50.                         if (participant.ContainsKey(eventName))
  51.                         {
  52.                             for (int i = 2; i < tokens.Length; i++)
  53.                             {
  54.                                 Match match = Regex.Match(tokens[i], pattern);
  55.                                 if (match.Success)
  56.                                 {
  57.                                     if (!participant[eventName].Contains(tokens[i]))
  58.                                     {
  59.                                         participant[eventName].Add(tokens[i]);
  60.                                     }
  61.                                 }
  62.                             }
  63.                         }
  64.                     }                  
  65.                 }
  66.             }
  67.             foreach (var kvp in participant.OrderByDescending(x => x.Value.Count).ThenBy(x => x.Key))
  68.             {
  69.                 string name = kvp.Key.Substring(1);
  70.                 Console.WriteLine("{0} - {1}", name, kvp.Value.Count);
  71.                 var tempPart = kvp.Value;
  72.                 foreach (var part in tempPart.OrderBy(x => x))
  73.                 {
  74.                     Console.WriteLine(part);
  75.                 }
  76.             }
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement