Beispiel #1
0
        public void Start()
        {
            List <Automate> listAutomate = new List <Automate>();

            for (int i = 0; i < 7; i++)
            {
                string nameFile = "input" + (i + 1) + ".txt";
                ReadFile(nameFile);
                listAutomate.Add(new Automate(ReadFile(nameFile)));
            }
            listAutomate[4].alphabet[0] = automateSpace.ElementAt(0).Key; //tab \t
            listAutomate[4].alphabet[1] = automateSpace.ElementAt(1).Key; //\r
            listAutomate[4].alphabet[2] = automateSpace.ElementAt(2).Key; //New Line \n
            listAutomate[4].alphabet[3] = automateSpace.ElementAt(3).Key; //Space \s
            listAutomate[4].alphabet[4] = automateSpace.ElementAt(4).Key; //tab \v
            StreamReader    objReader = new StreamReader("inputText.txt");
            string          str       = objReader.ReadToEnd();
            int             k         = 0;
            Result          result;
            MaxStringResult maxSubString;
            List <string>   answerList = new List <string>();

            for (int i = 0; i < str.Length;)
            {
                maxSubString = new MaxStringResult(0);
                foreach (Automate a in listAutomate)
                {
                    result = MaxString(a, str, k);
                    if (result.res == true && (result.m > maxSubString.m || (result.m == maxSubString.m && a.priority < maxSubString.priority)))
                    {
                        maxSubString.maxString    = result.substring;
                        maxSubString.nameAutomate = a.name;
                        maxSubString.m            = result.m;
                        maxSubString.priority     = a.priority;
                    }
                }
                if (maxSubString.maxString.Length != 0)
                {
                    k += maxSubString.maxString.Length;
                    i  = k;
                    if (maxSubString.nameAutomate == "Space")
                    {
                        string newFormat = "";
                        foreach (var c in maxSubString.maxString)
                        {
                            newFormat += automateSpace[c];
                        }
                        maxSubString.maxString = newFormat;
                    }
                    answerList.Add("<" + maxSubString.nameAutomate + "," + maxSubString.maxString + ">");
                }
                else
                {
                    answerList.Add("<Error," + str[k] + ">");
                    k++;
                    i++;
                }
            }
            WriteIntoFile("output.txt", answerList);
        }
        public List <MaxStringResult> Start(List <Automate> listAutomate)
        {
            StreamReader           objReader = new StreamReader("inputText.txt");
            string                 str       = objReader.ReadToEnd();
            int                    k         = 0;
            Result                 result;
            MaxStringResult        maxSubString;
            List <string>          answerList = new List <string>();
            List <MaxStringResult> listTokens = new List <MaxStringResult>();

            for (int i = 0; i < str.Length;)
            {
                maxSubString = new MaxStringResult(0);
                foreach (Automate a in listAutomate)
                {
                    result = MaxString(a, str, k);
                    if (result.res == true && (result.m > maxSubString.m || (result.m == maxSubString.m && a.priority < maxSubString.priority)))
                    {
                        maxSubString.maxString    = result.substring;
                        maxSubString.nameAutomate = a.name;
                        maxSubString.m            = result.m;
                        maxSubString.priority     = a.priority;
                    }
                }
                if (maxSubString.maxString.Length != 0)
                {
                    k += maxSubString.maxString.Length;
                    i  = k;
                    if (maxSubString.nameAutomate == "Space")
                    {
                        string newFormat = "";
                        foreach (var c in maxSubString.maxString)
                        {
                            newFormat += automateSpace[c];
                        }
                        maxSubString.maxString = newFormat;
                    }
                    answerList.Add("<" + maxSubString.nameAutomate + "," + maxSubString.maxString + ">");
                    if (maxSubString.nameAutomate != "Space")
                    {
                        listTokens.Add(maxSubString);
                    }
                }
                else
                {
                    answerList.Add("<Error," + str[k] + ">");
                    k++;
                    i++;
                }
            }
            WriteIntoFile("output.txt", answerList);
            return(listTokens);
        }