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 RoliTheCoder
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<Event> allEvents = new List<Event>();
- string inputLine = Console.ReadLine();
- while (!inputLine.Equals("Time for Code"))
- {
- bool inputIsValid = CheckIfTheInputLineIsValid(inputLine.Trim());
- if (!inputIsValid)
- {
- inputLine = Console.ReadLine();
- continue;
- }
- string[] eventInfo = inputLine.Trim().
- Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- int eventID = int.Parse(eventInfo[0]);
- string eventName = eventInfo[1].TrimStart('#');
- List<string> participants = new List<string>();
- participants = FillTheParticipantsIntoTheList(participants, eventInfo);
- if (allEvents.Any(i => i.ID == eventID))
- {
- Event excistingEvent = allEvents.First(i => i.ID == eventID);
- if (!excistingEvent.EventName.Equals(eventName))
- {
- inputLine = Console.ReadLine();
- continue;
- }
- excistingEvent.EventParticipants.AddRange(participants);
- excistingEvent.EventParticipants = excistingEvent.EventParticipants.Distinct().ToList();
- inputLine = Console.ReadLine();
- continue;
- }
- Event eventToAdd = new Event();
- eventToAdd.ID = eventID;
- eventToAdd.EventName = eventName;
- eventToAdd.EventParticipants.AddRange(participants);
- allEvents.Add(eventToAdd);
- inputLine = Console.ReadLine();
- }
- PrintResult(allEvents);
- }
- private static void PrintResult(List<Event> allEvents)
- {
- foreach (Event currEvent in allEvents.
- OrderByDescending(x => x.EventParticipants.Count).
- ThenBy(n => n.EventName))
- {
- Console.WriteLine($"{currEvent.EventName} - {currEvent.EventParticipants.Count}");
- foreach (string participant in currEvent.EventParticipants.OrderBy(x => x))
- {
- Console.WriteLine(participant);
- }
- }
- }
- private static List<string> FillTheParticipantsIntoTheList(List<string> participants, string[] eventInfo)
- {
- for (int currParticipant = 2; currParticipant < eventInfo.Length; currParticipant++)
- {
- participants.Add(eventInfo[currParticipant]);
- }
- return participants;
- }
- private static bool CheckIfTheInputLineIsValid(string inputLine)
- {
- Regex checker = new Regex(@"^([0-9]+\s+#\w+(\s+@\w+)*)");
- string match = checker.Match(inputLine).Groups[1].ToString();
- return inputLine.Length == match.Length;
- }
- }
- class Event
- {
- public Event()
- {
- EventParticipants = new List<string>();
- }
- public int ID { get; set; }
- public string EventName { get; set; }
- public List<string> EventParticipants { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement