Beispiel #1
0
        public CoupleOfCharacters FindMostCommonSequence(String inputedString)
        {
            var currentCouple    = new CoupleOfCharacters();
            var coupleForCompare = new CoupleOfCharacters();
            var maxMatchesCouple = new CoupleOfCharacters();
            var List             = new List <CoupleOfCharacters>();

            for (var i = 0; i < inputedString.Length - 1; i++)
            {
                currentCouple.FirstCharacter  = inputedString[i];
                currentCouple.SecondCharacter = inputedString[++i];
                currentCouple.AmountOfmatches = 0;
                i--;

                for (var j = i; j < inputedString.Length - 1; j++)
                {
                    coupleForCompare.FirstCharacter  = inputedString[j];
                    coupleForCompare.SecondCharacter = inputedString[++j];
                    j--;
                    currentCouple.CountMatches(coupleForCompare);
                }
                List.Add(currentCouple);
            }

            foreach (var i in List)
            {
                if (List.Select(p => p.AmountOfmatches).Max() == i.AmountOfmatches)
                {
                    maxMatchesCouple = i;
                }
            }
            return(maxMatchesCouple);
        }
 public int CountMatches(CoupleOfCharacters compare)
 {
     AmountOfmatches += ((FirstCharacter == compare.FirstCharacter) && (SecondCharacter == compare.SecondCharacter)) ? 1 : 0;
     return(AmountOfmatches);
 }