private static IReadOnlyList <FoundEntry> FindEntries(InputParseResult input) { var foundEntries = new List <FoundEntry>(); AhoAutomat ahoAutomat = GetAhoAutomatWithBuildedBohr(input.Entries); Dictionary <string, string> caseSensitiveEntries = input.Entries .ToDictionary(x => x.ToLower(), x => x); for (int lineNumber = 0; lineNumber < input.Lines.Count; lineNumber++) { string line = input.Lines[lineNumber]; for (int charPosition = 0; charPosition < line.Length; charPosition++) { char ch = line[charPosition]; ahoAutomat.SetNextState(char.ToLowerInvariant(ch)); IReadOnlyList <string> currentEntries = ahoAutomat.GetCurrentEntries(); foreach (string currentEntry in currentEntries) { var entryWithEndPosition = new FoundEntry { Line = lineNumber, Position = charPosition, Word = caseSensitiveEntries[currentEntry] }; foundEntries.Add(BuildEntryWithStartPosition(input.Lines, entryWithEndPosition)); } } ahoAutomat.SetNextState(' '); } return(foundEntries); }
static void Main() { InputParseResult input = ParseInput("input.txt"); IReadOnlyList <FoundEntry> foundEntries = FindEntries(input); PrintResult(foundEntries, "../../../out.txt"); }