示例#1
0
        public int Solve()
        {
            List <string> FinalCommandList = CommandArgInputParser.ConvertCommandListToList(SolveSettings);

            FinalCommandList.Add(fileParser.FilePath);
            string[] args       = FinalCommandList.ToArray();
            int      ResultCode = get_wordchain(args, args.Length);

            return(ResultCode);
        }
示例#2
0
        public void Solve()
        {
            int DllReturnCode = -1;

            commandArgInputParser = new CommandArgInputParser(CommandLineArgInput);
            commandArgInputParser.Parse();
            if (commandArgInputParser.CommandLegal)
            {
                if (commandArgInputParser.CommandDuplicated)
                {
                    /*
                     * Console.WriteLine("Input command settings has duplicate commands: "
                     + CommandArgInputParser.ConvertCommandListToString(commandArgInputParser.GetParsedCommandList()));
                     + Console.WriteLine("Derived an non-duplicated version of input command:"
                     + CommandArgInputParser.ConvertCommandListToString(commandArgInputParser.GetParsedCommandList(true)));
                     + Console.WriteLine("Enter 'y' to use the distinct command");
                     + int UseDistinctInput = Console.Read();
                     + if (UseDistinctInput == int.Parse("y"))
                     + {
                     +  longestPathSolver = new LongestPathSolver(commandArgInputParser.GetParsedCommandList(true), commandArgInputParser.FilePath);
                     +  DllReturnCode = longestPathSolver.Solve();
                     +
                     + }
                     + else
                     + {
                     +  Console.WriteLine("Exit : duplicated input command");
                     +  return;
                     + }*/
                    Console.WriteLine("Exit : Command duplicated");
                    return;
                }
                else
                {
                    longestPathSolver = new LongestPathSolver(commandArgInputParser.GetParsedCommandList(), commandArgInputParser.FilePath);
                    DllReturnCode     = longestPathSolver.Solve();
                }

                //check return code to check if there is any file exception or finished normally
                switch (DllReturnCode)
                {
                case 0:
                    Console.WriteLine("Solve finished");
                    return;

                case 1:
                    //file open exception:
                    longestPathSolver.fileParser.FileOpenFailed = true;
                    return;

                case 2:
                    //file contains illegalk circle without -r command
                    longestPathSolver.fileParser.IllegalFileOnNonRCommand = true;
                    return;

                default:
                    return;
                }
            }
            else
            {
                Console.WriteLine("Exit : Input command illegal");
                return;
            }
        }
示例#3
0
        private static int gen_chain(string[] words, int len, string[] result, char head, char tail, bool enable_loop, bool count_by_word, bool count_by_char)
        {
            List <string> InitialCommand = new List <string>();

            if (head != '\0')
            {
                InitialCommand.Add("-h");
                InitialCommand.Add(head.ToString());
            }

            if (tail != '\0')
            {
                InitialCommand.Add("-t");
                InitialCommand.Add(tail.ToString());
            }

            if (enable_loop)
            {
                InitialCommand.Add("-r");
            }

            if (count_by_char)
            {
                InitialCommand.Add("-c");
            }

            if (count_by_word)
            {
                InitialCommand.Add("-w");
            }
            InitialCommand.Add("FilePathTooken");
            CommandArgInputParser Parser = new CommandArgInputParser(InitialCommand.ToArray());

            Parser.Parse();

            if (Parser.CommandLegal)
            {
                int[] CppDllReturnCode = new int[2];
                Marshal.Copy(
                    gen_chain_cpp(words, len, result, count_by_word, enable_loop, head, tail), CppDllReturnCode, 0, 2);
                switch (CppDllReturnCode[0])
                {
                case 0:
                    //Console.WriteLine("Dll exit normally");
                    return(CppDllReturnCode[1]);

                case 1:
                    try
                    {
                        throw new FileOpenFailed();
                    }
                    catch (FileOpenFailed e)
                    {
                        Console.WriteLine(e.Message);
                        return(-1);
                    }

                case 2:
                    try
                    {
                        throw new IllegalFileOnNonRCommand();
                    }
                    catch (IllegalFileOnNonRCommand e)
                    {
                        Console.WriteLine(e.Message);
                        return(-2);
                    }

                default:
                    Console.WriteLine("Exit : In default case, cppdll return an undefined code");
                    Console.WriteLine("Undefined return code :" + CppDllReturnCode[0].ToString() + " " + CppDllReturnCode[1].ToString());
                    return(0);
                }
            }
            else
            {
                Console.WriteLine("Exit : Input command illegal");
                return(0);
            }
        }