Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace RoliTheCoder
- {
- public class Roli
- {
- public static void Main(string[] args)
- {
- Dictionary<int, string> activitiesByEventName = new Dictionary<int, string>();
- Dictionary<int, List<string>> activitiesByParticipants = new Dictionary<int, List<string>>();
- ProcessInput(activitiesByEventName, activitiesByParticipants);
- PrintOutput(activitiesByEventName, activitiesByParticipants);
- }
- private static void PrintOutput(Dictionary<int, string> activitiesByEventName, Dictionary<int, List<string>> activitiesByParticipants)
- {
- foreach (KeyValuePair<int, List<string>> activity in activitiesByParticipants.OrderByDescending(ev => ev.Value.Count).ThenBy(ev => ev.Key))
- {
- Console.WriteLine("{0} - {1}", activitiesByEventName[activity.Key], activity.Value.Count);
- foreach (string participant in activity.Value.OrderBy(part => part))
- {
- Console.WriteLine(participant);
- }
- }
- }
- private static void ProcessInput(Dictionary<int, string> activitiesByEventName, Dictionary<int, List<string>> activitiesByParticipants)
- {
- string command = Console.ReadLine();
- while (command != "Time for Code")
- {
- string[] commandInfo = command.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- int id = int.Parse(commandInfo[0]);
- string eventName = commandInfo[1];
- List<string> participants = new List<string>(commandInfo.Skip(2));
- if (eventName[0] != '#')
- {
- command = Console.ReadLine();
- continue;
- }
- eventName = eventName.Substring(1);
- if (activitiesByEventName.ContainsKey(id))
- {
- if (activitiesByEventName[id] == eventName)
- {
- AddParticipants(activitiesByParticipants, participants, id);
- }
- }
- else
- {
- activitiesByEventName.Add(id, eventName);
- activitiesByParticipants.Add(id, participants.Distinct().ToList());
- }
- command = Console.ReadLine();
- }
- }
- public static void AddParticipants(Dictionary<int, List<string>> activitiesByParticipants,
- List<string> newParticipants, int id)
- {
- foreach (string participant in newParticipants.Distinct())
- {
- if (!activitiesByParticipants[id].Contains(participant))
- {
- activitiesByParticipants[id].Add(participant);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment