Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class Program
- {
- static void Main()
- {
- Dictionary<int, Dictionary<string, List<string>>> eventDict =
- new Dictionary<int, Dictionary<string, List<string>>>();
- string inputLine = Console.ReadLine();
- while (inputLine != "Time for Code")
- {
- string[] splitInput = inputLine.Split();
- bool isIDnumber = CheckIDifNumber(splitInput);
- bool hasHashAndAt = CheckForHashAndAt(splitInput);
- if (isIDnumber && hasHashAndAt)
- {
- int ID = int.Parse(splitInput[0]);
- string eventName = splitInput[1].Substring(1);
- List<string> names = GetNames(splitInput);
- if (!eventDict.ContainsKey(ID))
- {
- eventDict[ID] = new Dictionary<string, List<string>>();
- if (!eventDict[ID].ContainsKey(eventName))
- {
- eventDict[ID].Add(eventName, names);
- }
- }
- else
- {
- if (eventDict[ID].ContainsKey(eventName))
- {
- eventDict[ID][eventName].AddRange(names);
- }
- }
- }
- inputLine = Console.ReadLine();
- }
- Dictionary<string, List<string>> resultDictionary =
- new Dictionary<string, List<string>>();
- foreach (var IdEvent in eventDict)
- {
- foreach (var eventPeople in IdEvent.Value)
- {
- List<string> names = eventPeople.Value.Distinct().ToList();
- names.Sort();
- if (!resultDictionary.ContainsKey(eventPeople.Key))
- {
- resultDictionary[eventPeople.Key] = new List<string>();
- }
- resultDictionary[eventPeople.Key].AddRange(names);
- }
- }
- foreach (var eventPeople in resultDictionary.
- OrderBy(val => -val.Value.Count).ThenBy(eventName => eventName.Key))
- {
- string eventName = eventPeople.Key;
- int participantsCount = eventPeople.Value.Count;
- Console.WriteLine(eventName + " - " + participantsCount);
- for (int i = 0; i < eventPeople.Value.Count; i++)
- {
- Console.WriteLine(eventPeople.Value[i]);
- }
- }
- } //END MAIN
- //------------------------METHODS------------------------//
- // Put NAMES into array
- private static List<string> GetNames(string[] splitInput)
- {
- List<string> names = new List<string>();
- for (int i = 2; i < splitInput.Length; i++)
- {
- names.Add(splitInput[i]);
- }
- names = names.Distinct().ToList();
- return names;
- }
- // Check if event and names start with # and @
- private static bool CheckForHashAndAt(string[] splitInput)
- {
- string eventName = splitInput[1];
- bool hashTagEvent = eventName[0] == '#' ? true : false;
- bool atName = true;
- for (int i = 2; i < splitInput.Length; i++)
- {
- string name = splitInput[i];
- atName = name[0] == '@' ? true : false;
- if (atName == false)
- {
- break;
- }
- }
- bool checkInputFormat = hashTagEvent && atName == true ? true : false;
- return checkInputFormat;
- }
- // Check if ID is a number, not a letter
- static bool CheckIDifNumber(string[] splitInput)
- {
- bool isItNumber = true;
- try
- {
- int ID = int.Parse(splitInput[0]);
- }
- catch
- {
- isItNumber = false;
- }
- return isItNumber;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement