思路:把单词切割成两部分,在set中查找是否两部分都存在即可
package test;
import java.util.Scanner;
import java.util.TreeSet;
public class Test{
static TreeSet<String> set1 = new TreeSet<String>();
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String line = null;
System.out.println("input:");
while(!"".equals((line=sc.nextLine().toLowerCase()))){
set1.add(line);
}
sc.close();
for(String word:set1){
for(int i=0,len=word.length();i<len;i++){
String pre = word.substring(0,i);
String last = word.substring(i,len);
if(set1.contains(pre)&&set1.contains(last)){
System.out.println(word);
break;
}
}
}
}
}