Advertisement
stefanMinch3v

SoftUni/ProgrammingF/Exam3

Mar 14th, 2017
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.73 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. public class Roli_The_Coder
  9. {
  10.     public static void Main(string[] args)
  11.     {
  12.         string checkingPattern = @"#([a-zA-Z0-9@]+)";
  13.         Regex checkKey = new Regex(checkingPattern);
  14.  
  15.         string pattern = @"([a-zA-Z0-9@]+)";
  16.         Regex regexKey = new Regex(pattern);
  17.        
  18.         Dictionary<int, SortedDictionary<string, List<string>>> events = new Dictionary<int, SortedDictionary<string, List<string>>>();
  19.  
  20.         string input = Console.ReadLine();
  21.  
  22.         while (! input.Equals("Time for Code"))
  23.         {
  24.            
  25.             if (! checkKey.IsMatch(input))
  26.             {
  27.                 goto lastLine;
  28.             }
  29.  
  30.             MatchCollection collection = regexKey.Matches(input);
  31.             int id = 0;
  32.             string eventName = string.Empty;
  33.             List<string> participants = new List<string>();
  34.  
  35.             id = int.Parse(collection[0].Groups[0].ToString());
  36.             eventName = collection[1].Groups[0].ToString();
  37.  
  38.             for (int i = 2; i < collection.Count; i++)
  39.             {
  40.                 participants.Add(collection[i].Groups[0].ToString());
  41.             }
  42.  
  43.             FillOutDictionary(events, id, eventName, participants);
  44.  
  45.             lastLine: input = Console.ReadLine();
  46.         }
  47.  
  48.         PrintOutInfo(events);
  49.        
  50.     }
  51.  
  52.     private static void PrintOutInfo(Dictionary<int, SortedDictionary<string, List<string>>> events)
  53.     {
  54.         var finalResult = events.OrderByDescending(a => a.Value.Values.Sum(p => p.Count));
  55.         foreach (var item in finalResult)
  56.         {
  57.             foreach (var data1 in item.Value)
  58.             {
  59.                 Console.WriteLine($"{data1.Key} - {data1.Value.Distinct().Count()}");
  60.             }
  61.             foreach (var data in item.Value.Values)
  62.             {
  63.                 foreach (var save in data.Distinct().OrderBy(n => n))
  64.                 {
  65.                     Console.WriteLine(save);
  66.                 }
  67.             }
  68.         }
  69.     }
  70.  
  71.     private static void FillOutDictionary(Dictionary<int, SortedDictionary<string, List<string>>> events, int id, string eventName, List<string> participants)
  72.     {
  73.         if (! events.ContainsKey(id))
  74.         {
  75.             events.Add(id, new SortedDictionary<string,  List<string>>());
  76.             events[id].Add(eventName, new List<string>());
  77.             events[id][eventName].AddRange(participants);
  78.         }
  79.         else
  80.         {
  81.             if (events[id].ContainsKey(eventName))
  82.             {
  83.                 events[id][eventName].AddRange(participants);
  84.             }
  85.         }
  86.        
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement