【发布时间】:2015-03-08 23:48:10
【问题描述】:
我有一个名为字典的数组列表,其中包含以下字母。 g,t,c,a,n,d,l,e,t,j,a,q。
我希望输出例如, 2蜡烛 3等 该数字是从正在搜索的数组开始的偏移量。
我希望输出是匹配位置的列表,每个位置都由文本开头的偏移量和找到的字符串组成。 请帮忙!!
【问题讨论】:
-
2can怎么了?
我有一个名为字典的数组列表,其中包含以下字母。 g,t,c,a,n,d,l,e,t,j,a,q。
我希望输出例如, 2蜡烛 3等 该数字是从正在搜索的数组开始的偏移量。
我希望输出是匹配位置的列表,每个位置都由文本开头的偏移量和找到的字符串组成。 请帮忙!!
【问题讨论】:
如果我们考虑这种类型的问题,关键是要找出所有不同的可能性,以便在您可以找到单词的地方找到。这是我编写的用于处理此过程的方法的框架:
public static String findWords(final char[] characters) {
String toRet = "";
// First iterate through every character in the array characters.
for (int i = 0; i < characters.length; i++) {
/*
* Then at each step in this loop, check all possible word
* combinations to see if it's a word. For example, check and see if
* characters[i], characters[i+1] forms a word. Then check and see
* if the word made by adding together characters[i],
* characters[i+1], and characters[i+2] is a word. Then check and
* see if the word formed by adding together the characters
* characters[i], characters[i+1], characters[i+2], characters[i+3]
* is a word.
*/
// Doing the above requires a nested loop inside of the original
// loop.
for (int j = 0; j < characters.length - i; j++) {
// When you do find a word that is formed, then go ahead and add
// to your string toRet the details about the word formed.
}
}
return toRet;
}
这并不能完全回答你的问题,但我希望它
【讨论】: