예제 #1
0
 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);
     }
 }
예제 #2
0
 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);
     }
 }
예제 #3
0
        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(' ');
            }
        }
예제 #4
0
 public static void HandleAdd(KFrequentNumberSolution frequentNumbers, int number)
 {
     frequentNumbers.Add(number);
     Console.WriteLine("Ok: {0} added", number);
 }