查找具有给定单词的所有字符的所有单词

编程入门 行业动态 更新时间:2024-10-24 19:25:50
本文介绍了查找具有给定单词的所有字符的所有单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在创建文字游戏。我在一个文本文件中列出了英语词典中所有单词的列表。我在此列表中选择一个随机词。一旦有了随机词,就需要选择所有具有所选随机词中所有字符的词。

I am creating a word game. I have a list of all the words in the english dictionary in a text file. I choose a random word in this list. Once I have the random word then I need to choose all the words that have all the characters in the choosen random word.

我需要一种策略来做到这一点。另外,我应该将单词列表放置在文本文件还是数据库中。最好的策略是什么?

I need a strategy to do this. Also, shall i place the word list in a text file or a database. What is the best strategy to do this?

编辑

匹配示例:

  • The匹配他,他、,、 te NOT-> Thee,Tee
  • 如您在上面的示例中看到的, foil匹配油,如果不是->填充,傻瓜,掉油,

随机单词不能与具有更多字符的单词或具有比单个单词更多的单个字符的单词匹配

As you can see in the above examples the random word must not match words that have more characters or characters that have more of a single character then the random word

例如:

  • e必须与ee不匹配
  • el必须与eel不匹配
  • 很多不能与赃物匹配
推荐答案

对于使用拉丁字母的语言中的单词,您可以计算单词的26位只有在单词包含字母#i时,才将位#i设置为1。

For words in languages that use latin alphabet, you can calculate word's 26-bit "signature" by setting bit #i to one only when the word contains letter #i of the alphabet:

var signature = 0; foreach (var c in word.ToUpperCase()) { signature |= (1<<(c-'A')); }

然后可以将签名及其词和词的长度存储在数据库。单词匹配后,需要计算其签名,然后在数据库中查询所有与签名和目标单词长度匹配的单词。对于每个具有匹配长度和签名的候选单词,将其转换为大写字母,对其字母排序,然后将排序结果与排序目标进行比较。如果目标匹配,则将单词添加到答案列表中。

You can then store the signature along with its word and the word's length in the database. Once you get the word you need to match, calculate its signature, and query the database for all words that match the signature and the target words's length. For each candidate word with matching length and signature, convert the word to upper case, sort its letters, and compare the sorted result to sorted target. If the target matches, add the word to the list of answers.

更多推荐

查找具有给定单词的所有字符的所有单词

本文发布于:2023-10-26 11:55:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530061.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单词   字符

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!