Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace _04_roliCoder
- {
- class Event
- {
- public string Name { get; set; }
- public List<string> Participants { get; set; }
- public Event(string name,List<string> participants)
- {
- Name = name;
- Participants = participants;
- }
- }
- class roliCoder
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- string pattern = @"^(?<id>\d+) #(?<name>[\w]*)(?<participants>\s?@\w+)*$";
- Dictionary<int, Event> events = new Dictionary<int, Event>();
- while (input != "Time for Code")
- {
- Match currMatch = Regex.Match(input, pattern);
- if (currMatch.Success)
- {
- int id = int.Parse(currMatch.Groups["id"].Value);
- string name = currMatch.Groups["name"].Value;
- string[] inputTokkens = input.Split(new string[]{ " @", }, StringSplitOptions.RemoveEmptyEntries);
- List<string> currParticipants = new List<string>();
- for (int i = 1; i < inputTokkens.Length; i++)
- {
- currParticipants.Add(inputTokkens[i]);
- }
- if (!events.ContainsKey(id))
- {
- events.Add(id, new Event(name, currParticipants));
- }
- else
- {
- if(events[id].Name == name)
- {
- events[id].Participants.AddRange(currParticipants);
- }
- }
- }
- input = Console.ReadLine();
- }
- var orderedEvents = events
- .OrderByDescending(ev => ev.Value.Participants.Count)
- .ThenBy(ev => ev.Value.Name);
- foreach (var orderedEvent in orderedEvents)
- {
- string eventName = orderedEvent.Value.Name;
- List<string> guests = orderedEvent.Value.Participants;
- int atendance = orderedEvent.Value.Participants.Distinct().Count();
- Console.WriteLine("{0} - {1}", eventName, atendance);
- List<string> orderedGuests = new List<string>();
- foreach (var guest in guests)
- {
- if (!orderedGuests.Contains("@" + guest))
- {
- orderedGuests.Add("@" + guest);
- }
- }
- orderedGuests.Sort();
- Console.WriteLine(string.Join("\r\n", orderedGuests));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement