Advertisement
valkata

RoliCoder

Aug 16th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.02 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. namespace _04_roliCoder
  9. {
  10.     class Event
  11.     {
  12.         public string  Name { get; set; }
  13.         public List<string> Participants { get; set; }
  14.  
  15.         public Event(string name,List<string> participants)
  16.         {
  17.             Name = name;
  18.             Participants = participants;
  19.         }        
  20.     }
  21.     class roliCoder
  22.     {
  23.         static void Main(string[] args)
  24.         {
  25.             string input = Console.ReadLine();
  26.             string pattern = @"^(?<id>\d+) #(?<name>[\w]*)(?<participants>\s?@\w+)*$";
  27.  
  28.             Dictionary<int, Event> events = new Dictionary<int, Event>();
  29.  
  30.             while (input != "Time for Code")
  31.             {
  32.                 Match currMatch = Regex.Match(input, pattern);
  33.                 if (currMatch.Success)
  34.                 {
  35.                     int id = int.Parse(currMatch.Groups["id"].Value);
  36.                     string name = currMatch.Groups["name"].Value;
  37.                     string[] inputTokkens = input.Split(new string[]{ " @", }, StringSplitOptions.RemoveEmptyEntries);
  38.                     List<string> currParticipants = new List<string>();
  39.                     for (int i = 1; i < inputTokkens.Length; i++)
  40.                     {
  41.                         currParticipants.Add(inputTokkens[i]);
  42.                     }
  43.  
  44.                     if (!events.ContainsKey(id))
  45.                     {
  46.                         events.Add(id, new Event(name, currParticipants));
  47.                     }
  48.                     else
  49.                     {
  50.                         if(events[id].Name == name)
  51.                         {
  52.                             events[id].Participants.AddRange(currParticipants);
  53.                         }
  54.                     }
  55.                 }                
  56.                 input = Console.ReadLine();          
  57.             }
  58.  
  59.             var orderedEvents = events
  60.                 .OrderByDescending(ev => ev.Value.Participants.Count)
  61.                 .ThenBy(ev => ev.Value.Name);
  62.  
  63.            
  64.             foreach (var orderedEvent in orderedEvents)
  65.             {
  66.                 string eventName = orderedEvent.Value.Name;              
  67.                
  68.                 List<string> guests = orderedEvent.Value.Participants;
  69.  
  70.                 int atendance = orderedEvent.Value.Participants.Distinct().Count();
  71.                 Console.WriteLine("{0} - {1}", eventName, atendance);
  72.  
  73.                 List<string> orderedGuests = new List<string>();
  74.                 foreach (var guest in guests)
  75.                 {
  76.                     if (!orderedGuests.Contains("@" + guest))
  77.                     {
  78.                         orderedGuests.Add("@" + guest);
  79.                     }                    
  80.                 }
  81.                 orderedGuests.Sort();
  82.                
  83.                 Console.WriteLine(string.Join("\r\n", orderedGuests));
  84.             }          
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement