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 RoliNested
- {
- public static void Main(string[] args)
- {
- Dictionary<int, Dictionary<string, List<string>>> data = ReadData();
- PrintOutput(data);
- }
- private static void PrintOutput(Dictionary<int, Dictionary<string, List<string>>> data)
- {
- foreach (Dictionary<string, List<string>> dict in data.Values.OrderByDescending(ev => ev.Values.Sum(participants => participants.Count)).ThenBy(
- ev => ev.Keys.FirstOrDefault()))
- {
- foreach (KeyValuePair<string, List<string>> ev in dict)
- {
- Console.WriteLine("{0} - {1}", ev.Key, ev.Value.Count);
- foreach (string participant in ev.Value.OrderBy(part => part))
- {
- Console.WriteLine(participant);
- }
- }
- }
- }
- private static Dictionary<int, Dictionary<string, List<string>>> ReadData()
- {
- string inputData = Console.ReadLine();
- Dictionary<int, Dictionary<string, List<string>>> data =
- new Dictionary<int, Dictionary<string, List<string>>>();
- while (inputData != "Time for Code")
- {
- string[] commandInfo = inputData.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] != '#')
- {
- inputData = Console.ReadLine();
- continue;
- }
- eventName = eventName.Substring(1);
- if (data.ContainsKey(id))
- {
- if (data[id].ContainsKey(eventName))
- {
- data[id][eventName].AddRange(participants);
- data[id][eventName] = data[id][eventName].Distinct().ToList();
- }
- }
- else
- {
- Dictionary<string, List<string>> info = new Dictionary<string, List<string>>
- {
- {eventName, participants.Distinct().ToList()}
- };
- data.Add(id, info);
- }
- inputData = Console.ReadLine();
- }
- return data;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment