Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            TextReader      istream = MakeInput(TestData1.Item1);
            CWriterMediator ostream = MakeOutput(TestData1.Item2);

            TextReader std_in  = Console.In;
            TextWriter std_out = Console.Out;

            Console.SetIn(istream);
            Console.SetOut(ostream);


            //   IO-цепочки для ввода-вывода.
            CIO io = new CIO();

            if (io.In(io.Number(out int n_vals), io.InEOL()))
            {
                while (n_vals > 0)
                {
                    if (io.Number(out int cmd_code).Success)
                    {
                        switch (cmd_code)
                        {
                        case 1:
                        {
                            if (io.In(io.OneOf(" "), io.Number(out int x_val)))
                            {
                                ConsoleEx.MsgBox($"c = {cmd_code}, val = {x_val}");
                            }
                            else
                            {
                                goto InvalidInput;
                            }
                        }
                        break;

                        case 2:
                        {
                            ConsoleEx.MsgBox($"c = {cmd_code}");
                        }
                        break;

                        case 3:
                        {
                            ConsoleEx.MsgBox($"c = {cmd_code}");
                        }
                        break;

                        default: goto InvalidInput;
                        }

                        if (!io.InEOL().Success)
                        {
                            goto InvalidInput;
                        }
                    }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //TextReader tx1 = File.OpenText(@"D:\DESKTOP\Code\Examples_HackerRank\bin\Debug\Cases\Data Structures\Stack\Cache Maximums\input00.txt");
            //Console.SetIn(tx1);
            //TextReader tx2 = Console.In;
            //int d = tx2.Read();
            //return;


            CExercise run_exe;

            var exe_list = new List <CExercise>
            {
                (run_exe = new DataStructures.Stack.CECacheMaximums()),
                new DataStructures.Stack.CEBalancedBrackets(),
            };

            var exercises = new Dictionary <string, CExercise> ();

            foreach (CExercise exe_item in exe_list)
            {
                exercises.Add(exe_item.ID, exe_item);
            }
            ;

            CExercise exe = exercises[run_exe.ID];

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.BackgroundColor = ConsoleColor.DarkMagenta;
            Console.WriteLine(exe.ExerciseHint.PadRight(Console.BufferWidth));
            Console.CursorTop--;
            Console.ResetColor();

            //int case_num = 1;
            foreach (TestCase test_case in exe.TestCases)
            {
                Console.ForegroundColor = ConsoleColor.DarkGray;
                Console.BackgroundColor = ConsoleColor.Black;
                Console.Write(exe.CaseHint(test_case, $"Case") + " RUN...");

                TextReader      istream = MakeInput(test_case.InputFile);
                CWriterMediator ostream = MakeOutput(test_case.OutputFile);

                TextReader std_in  = Console.In;
                TextWriter std_out = Console.Out;

                Console.SetIn(istream);
                Console.SetOut(ostream);

                Exception fail_result = null;
                try
                {
                    CIO io = new CIO(Console.In);
                    exe.Execute(io);
                }
                catch (Exception e)
                {
                    fail_result = e;
                }

                Console.SetIn(std_in);
                Console.SetOut(std_out);

                Console.CursorLeft -= 6;
                if ((ostream.Mismatches > 0) || (fail_result != null))
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine($"FAIL   "); // ostream.Mismatches
                    Console.CursorTop--;
                    Console.WriteLine("   - ");
                    Console.ResetColor();

                    if (fail_result != null)
                    {
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        Console.WriteLine(fail_result.Message);
                        Console.ResetColor();
                    }
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine($"PASS   "); // ostream.Mismatches
                    Console.CursorTop--;
                    Console.WriteLine("   + ");
                    Console.ResetColor();
                }
            }

            Console.WriteLine($"Press any key to quit...");
            Console.ReadKey();
        }