因此,我正在编写一个拼字游戏建议程序,我决定这样做,因为我想学习集(不用担心,我至少得到了这个部分),并引用了程序中未创建的信息/数据。我对Java很熟悉(一般编程),但我想知道如何从单词列表中提取单词.FIC文件,以检查它们是否与输入字母生成的单词相对应。如何从java中的.FIC文件中提取数据?
为了澄清,我编写了一个程序,它会接收一系列字母,并返回从这些字母中创建的每个可能单词的集合。例如: 输入:
abc
会得包含“字”一组:
a, ab, ac, abc, acb, b, ba, bc, bac, bca, c, ca, cb, cab, cba
什么我问,果然,是如何检查那些找到包含在的人。 FIC文件。
该文件是Moby project word list中的“官方纵横字谜”文件,我仍然(非常)在解析和其他文件处理方法上很不稳定。我继续研究,所以我没有任何原型代码。
对不起,如果问题不完全清楚。
编辑:这里是让“单词”更容易理解这个想法的方法。我不明白的部分是如何从.FIC文件中拉出单词(作为字符串)。
private static Set<String> Words(String s)
{
Set<String> tempwords = new TreeSet<String>();
if (s.length() == 1)
{ // base case, last letter
tempwords.add(s);
// System.out.println(s); uncomment when debugging
}
else
{
//set up to add each letter in s
for (int i = 0; i < s.length(); i++)
{ //cut the i letter out of the string
String remaining = s.substring(0, i) + s.substring(i+1);
//recursion to add all combinations of letters onto the current letter/"word"
for (String permutation : Words(remaining))
{
// System.out.println(s.substring(i, i+1) + permutation); uncomment when debugging
//add the full length words
tempwords.add(s.substring(i, i+1) + permutation);
// System.out.println(permutation); uncomment when debugging
//add the not-full-length words
tempwords.add(permutation);
}
}
}
// System.out.println(tempwords); uncomment when debugging
return tempwords;
}
什么是.FIC文件? (向我们展示一个示例文件,您的解析和搜索/匹配代码,您期望代码执行的内容以及实际执行的内容。) – 2014-10-12 01:03:15
这只是一个单词列表,每行一个。只需要按行读取文件并将这些文字添加到散列映射或特里结构中以进行匹配。 – hobbs 2014-10-12 01:19:32