public void FirstTask()
        {
            WorkWithFileClass    workWithFileClass    = new WorkWithFileClass();
            WorkWithConsoleClass workWithConsoleClass = new WorkWithConsoleClass();

            string   realInputFileName = Directory.GetCurrentDirectory() + "/input.txt";
            DfaClass dfaClass          = new DfaClass(workWithFileClass.ReadDfaInformationFromFile(realInputFileName));

            workWithFileClass.PrintDfaToFile(dfaClass);

            string str = workWithConsoleClass.FirstTaskConsoleInput();

            int k = 0;

            while (k < str.Length)
            {
                var maxRes = dfaClass.MaxString(str, k);
                if (maxRes.Key == true)
                {
                    workWithConsoleClass.FirstTaskConsoleOutput(str.Substring(k, maxRes.Value));
                    k += Math.Max(maxRes.Value, 1);
                }
                else
                {
                    k++;
                }
            }
        }
示例#2
0
        public void PrintDfaToFile(DfaClass dfa)
        {
            File.WriteAllText(_outputFileName, String.Empty);
            using (StreamWriter writer = new StreamWriter(_outputFileName, true))
            {
                foreach (var stateForOutput in dfa.States)
                {
                    writer.WriteLine("Priority:");
                    writer.WriteLine(dfa.Priority);
                    writer.WriteLine("State:");
                    writer.WriteLine(stateForOutput.NameOfState);
                    if (stateForOutput.AvailableStates.Count > 0)
                    {
                        writer.WriteLine("Available States:");
                        foreach (var state in stateForOutput.AvailableStates)
                        {
                            writer.Write(state + " ");
                        }

                        writer.WriteLine();
                        writer.WriteLine("State Transition Signals:");
                        int i = 0;
                        foreach (var signalList in stateForOutput.StateTransitionSignals)
                        {
                            writer.Write(stateForOutput.NameOfState + " --> " + stateForOutput.AvailableStates[i] +
                                         " by signals: ");
                            foreach (var signal in signalList)
                            {
                                writer.Write(signal + " ");
                            }

                            writer.WriteLine();
                            i++;
                        }
                    }
                    else
                    {
                        writer.WriteLine("No Available States");
                        writer.WriteLine("No State Transition Signals");
                    }
                    writer.WriteLine();
                }
                writer.WriteLine("Start States:");
                foreach (var elem in dfa.StartStates)
                {
                    writer.Write(elem + " ");
                }
                writer.WriteLine();
                writer.WriteLine("Final States:");

                foreach (var elem in dfa.FinalStates)
                {
                    writer.Write(elem + " ");
                }
            }
        }