public static void HandleRemove(KFrequentNumberSolution frequentNumbers, int number) { if (frequentNumbers.Remove(number)) { Console.WriteLine("Ok: Number {0} removed", number); } else { Console.WriteLine("Error: Number {0} not found", number); } }
public static void HandleGet(KFrequentNumberSolution frequentNumbers, int k) { try { var number = frequentNumbers.GetKMostFrequent(k); Console.WriteLine("Ok: Found {0}", number); } catch { Console.WriteLine("Error: {0} is invalid K", k); } }
public static void Main() { //FakeInput(); var frequentNumbers = new KFrequentNumberSolution(); var commands = new Dictionary <string, Action <KFrequentNumberSolution, int> >() { { "ADD", HandleAdd }, { "REMOVE", HandleRemove }, { "GET", HandleGet } }; var command = Console.ReadLine().Split(' '); while (command[0] != COMMAND_END) { commands[command[0]](frequentNumbers, int.Parse(command[1])); command = Console.ReadLine().Split(' '); } }
public static void HandleAdd(KFrequentNumberSolution frequentNumbers, int number) { frequentNumbers.Add(number); Console.WriteLine("Ok: {0} added", number); }