Advertisement
Guest User

Untitled

a guest
Feb 11th, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Organizer
  6. {
  7.     public static void Main() // 100/100
  8.     {
  9.         string input = Console.ReadLine();
  10.         Dictionary<int, string> eventsById = new Dictionary<int, string>();
  11.         Dictionary<string, List<string>> organizer = new Dictionary<string, List<string>>();
  12.  
  13.         while (input != "Time for Code")
  14.         {
  15.             if (input.Contains("#"))
  16.             {
  17.                 List<string> eventInfo = input
  18.                     .Split(new char[] { ' ', '#' }, StringSplitOptions.RemoveEmptyEntries)
  19.                     .ToList();
  20.  
  21.                 int id = int.Parse(eventInfo[0]);
  22.                 string eventName = eventInfo[1];
  23.  
  24.                 List<string> participants = new List<string>();
  25.  
  26.                 for (int i = 2; i < eventInfo.Count; i++)
  27.                 {
  28.                     participants.Add(eventInfo[i]);
  29.                 }
  30.                 if (!eventsById.ContainsKey(id))
  31.                 {
  32.                     eventsById.Add(id, eventName);
  33.                     organizer.Add(eventName, participants);
  34.                 }
  35.                 else if (eventsById[id] == eventName)
  36.                 {
  37.                     organizer[eventName].AddRange(participants);
  38.                 }
  39.             }
  40.  
  41.             input = Console.ReadLine();
  42.         }
  43.         foreach (KeyValuePair<string, List<string>> events in organizer.OrderByDescending(x => x.Value.Distinct().Count()).ThenBy(x => x.Key))
  44.         {
  45.             Console.WriteLine($"{events.Key} - {events.Value.Distinct().Count()}");
  46.             foreach (string participant in events.Value.OrderBy(x => x).Distinct())
  47.             {
  48.                 Console.WriteLine(participant);
  49.             }
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement