Example #1
0
        public static void Main()
        {
            Trie <int> trie = new Trie <int>();

            using (StreamReader reader = new StreamReader("..\\..\\PasswordsFromFaceBook.txt"))
            {
                while (!reader.EndOfStream)
                {
                    reader
                    .ReadLine()
                    .Split(' ', '.', ',', '?', '!', ':')
                    .ToList()
                    .ForEach(word =>
                    {
                        if (!trie.ContainsKey(word))
                        {
                            trie.Add(word, 1);
                        }
                        else
                        {
                            trie[word] += 1;
                        }
                    });
                }
            }

            //// Search is case sensitive.
            //// For reference open NotePad++ > Ctrl+F > 'lorem' > [√] MatchCase > Click Count
            trie.Matcher.Next("lorem");

            int countOfLorem = 0;

            if (trie.Matcher.IsMatch())
            {
                countOfLorem = trie.Matcher.GetExactMatch();
            }

            Console.WriteLine(countOfLorem);
            //// PF OMG that works
        }
        public static void Main()
        {
            Trie<int> trie = new Trie<int>();

            using (StreamReader reader = new StreamReader("..\\..\\input.txt"))
            {
                while (!reader.EndOfStream)
                {
                    reader
                        .ReadLine()
                        .Split(' ', '.', ',', '?', '!', ':')
                        .ToList()
                        .ForEach(word =>
                        {
                            if (!trie.ContainsKey(word))
                            {
                                trie.Add(word, 1);
                            }
                            else
                            {
                                trie[word] += 1;
                            }
                        });
                }
            }

            trie.Matcher.Next("lorem");

            int countOfLorem = 0;

            if (trie.Matcher.IsMatch())
            {
                countOfLorem = trie.Matcher.GetExactMatch();
            }

            Console.WriteLine(countOfLorem);
        }