示例#1
0
文件: Node.cs 项目: njmube/public
        private IEnumerable<string> InternalGetAnagrams(Dictionary<char, int> tiles, List<string> path, Node root,
                                                    int minLength, int minWordLength)
        {
            if (final && depth >= minWordLength)
              {
            var word = string.Join("", path);
            var length = word.Replace(" ", "").Length;
            if (length >= minLength)
              yield return word;

            using (new Guard(() => path.Push(" "), path.Pop))
            {
              foreach (var anagram in root.InternalGetAnagrams(tiles, path, root, minLength, minWordLength))
            yield return anagram;
            }
              }

              foreach (var child in children)
              {
            var l = child.Key;

            var count = tiles.Get(l);
            if (count == 0)
              continue;

            using (new Guard(() => tiles[l] = count - 1, () => tiles[l] = count))
            using (new Guard(() => path.Push(l.ToString()), path.Pop))
            {
              var node = child.Value;
              foreach (var anagram in node.InternalGetAnagrams(tiles, path, root, minLength, minWordLength))
            yield return anagram;
            }
              }
        }
示例#2
0
文件: MainForm.cs 项目: njmube/public
        private static Node LoadDictionary(string wordlist)
        {
            var result = new Node();

              wordlist
            .Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
            .Select(word => word.Trim().ToLowerInvariant())
            .ToList()
            .ForEach(result.Add);

              return result;
        }
示例#3
0
文件: MainForm.cs 项目: njmube/public
 private void MainForm_Load(object sender, EventArgs e)
 {
     dictionary = LoadDictionary(Resources.WordsList);
 }