Advertisement
GerganaTsirkova

RolliTheCoder

Apr 7th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _3.RoliTheCoder
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var dict = new Dictionary<string, Dictionary<string, List<string>>>();
  12.             while (true)
  13.             {
  14.                 string[] input = Console.ReadLine().Split().ToArray();
  15.                 bool isValid = true;
  16.                 if ((input[0] == "Time") && (input[1] == "for") && (input[2] == "Code"))
  17.                 {
  18.                     break;
  19.                 }
  20.                 if ((input.Length>=2)&&(!input[1].StartsWith("#")))
  21.                 {
  22.                     isValid = false;
  23.                 }
  24.                 for (int i = 2; i < input.Length; i++)
  25.                 {
  26.                     if (!input[i].StartsWith("@"))
  27.                     {
  28.                         isValid = false;
  29.                         break;
  30.                     }
  31.                 }
  32.                 if (isValid == false)
  33.                 {
  34.                     continue;
  35.                 }
  36.                 string id = input[0];
  37.                 string eventName = "";
  38.                 if (input.Length >= 2)
  39.                 {
  40.                     eventName += input[1].TrimStart('#');
  41.                 }
  42.                 var inner = new List<string>();
  43.                 for (int i = 2; i < input.Length; i++)
  44.                 {
  45.                     inner.Add(input[i]);
  46.                 }
  47.                 var innerList = inner.Distinct().ToList();
  48.                 if ((!dict.ContainsKey(id))&&(eventName !=""))
  49.                 {
  50.                     var innerDict = new Dictionary<string, List<string>>();
  51.                     innerDict.Add(eventName, innerList);
  52.                     dict.Add(id, innerDict);
  53.                 }
  54.                 else
  55.                 {
  56.                     if (dict[id].ContainsKey(eventName))
  57.                     {
  58.                         for (int i = 0; i < innerList.Count; i++)
  59.                         {
  60.                             if (!dict[id][eventName].Contains(innerList[i]))
  61.                             {
  62.                                 dict[id][eventName].Add(innerList[i]);
  63.                             }
  64.                         }
  65.  
  66.                     }
  67.                 }
  68.             }
  69.             if (dict.Count > 0)
  70.             {
  71.                 foreach (var i in dict.OrderByDescending(x => dict[x.Key].Values.First().Count))
  72.                 {
  73.                     foreach (var eventt in i.Value)
  74.                     {
  75.                         Console.WriteLine($"{eventt.Key} - {eventt.Value.Count}");
  76.                         foreach (var item in eventt.Value.OrderBy(x => x))
  77.                         {
  78.                             Console.WriteLine($"{item}");
  79.                         }
  80.                     }
  81.                 }
  82.             }
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement