Ejemplo n.º 1
0
 private static void HandlePancakeStrings(string[] args)
 {
     if (! int.TryParse(args[0], out var testCases)) 
         throw new Exception("Invalid test cases provided, must be an integer.");
     
     var pancakeSorter = new PancakeSorter();
     
     // Start at index 1 because that's the test cases int
     // Also only do as many testCases as provided, if they provide more ignore it
     for (var i = 1; i <= testCases && i < args.Length; i++)
     {
         var (_, numberOfExecutions) = pancakeSorter.SortRecursive(args[i]);
         Console.WriteLine($"Case #{i}: {numberOfExecutions}");
     }
 }
Ejemplo n.º 2
0
 private static void HandlePancakeStringsInteractive(int testCases)
 {
     var pancakeSorter = new PancakeSorter();
     
     Console.WriteLine("Begin pancake string input");
     for (var i = 0; i < testCases; i++)
     {
         var pancakeString = Console.ReadLine()?.Trim();
         while (!new InputValidator().IsValidPancakeString(pancakeString))
         {
             Console.WriteLine("Invalid pancake string, try again. (only + and - are allowed)");
             pancakeString = Console.ReadLine()?.Trim();
         }
         
         var (_, numberOfExecutions) = pancakeSorter.Sort(pancakeString);
         Console.WriteLine($"Case #{i + 1}: {numberOfExecutions}");
     }
 }