import java.util.Vector;public class Test { private String[]cubes=new String[]{"abcdef","defghi","hijklm","nopqrs","tuvwxy"};
private String[]words=new String[]{"admin","flex","aeiou"};
private Vector <String> centerCube=new Vector <String>();
private String[] srt;
//private int outInt;
public void Test(){}
public void setVector(String[]ss){
for(int i=0;i<ss.length;i++){
centerCube.addElement(ss[i]);
}
//System.out.println("VectorCube size: "+centerCube.size());
} //ok public String[] VecToStr(Vector ev){
int size=ev.size();
//System.out.println("Vector Size: "+size);
String[] st=new String[size];
for(int i=0;i<ev.size();i++){
st[i]=ev.elementAt(i).toString();
} //测试代码,Vector转化为String调用函数
return st;
} //ok
public void printString(String[]sa){
System.out.print("");
//String[]words=new String[]{"admin","flex"};
for(int i=0;i<sa.length;i++){
System.out.print(sa[i]+" ");
} //测试代码,Vector转化为String调用函数
System.out.println();
} //ok
public void run(){
this.setVector(cubes);
srt=this.VecToStr(centerCube);
System.out.println("String[] length: "+srt.length);
System.out.print("String[] cubes: ");
this.printString(srt); //测试代码,Vector转化为String
System.out.print("String[] word: ");
this.printString(words);
/* centerCube.removeElement("abcdef");
srt=this.VecToStr(centerCube);
System.out.println("String[] length: "+srt.length);
this.printString(srt);*/ //测试代码,Vector转化为String
boolean a=compareVs(centerCube,"adi"); //判断adiji是否“包含”于集合类centerCube中,返回布尔类型a
System.out.println("Test a:"+a); //测试代码,结果显示递归成功
composeWord(cubes,words);
}
public void composeWord(String[] cub,String[]word)
{
System.out.print("Results: {");
for(int i=0;i<word.length;i++){
//System.out.println("hello");
if(compareVs(centerCube,word[i])){
//outInt=i;
System.out.print(i+", ");
//System.out.print("true ");
}
else{
//System.out.println("Word");
//System.out.print(" false");
}
setVector(cubes);
}
System.out.println("}");
}
public boolean compareLetter(String destWord,char sourceChar){
for(int i=0;i<destWord.length();i++){
if(destWord.charAt(i)==sourceChar){
return true;
}
}
return false;
} //ok
public boolean compareSC(Vector destV,char sourceC){
String[] destWs=VecToStr(destV);
for(int i=0;i<destWs.length;i++){
if(compareLetter(destWs[i],sourceC)){
centerCube.removeElement(destWs[i]); //remove StringElement OK
return true;
}
}
return false;
}
public boolean compareVs(Vector destVs,String word){
//String[] destWs=VecToStr(destVs);
String subWord=word;
char[] wordChar=subWord.toCharArray();
int subWordLen=subWord.length();
if(subWordLen==1){
setVector(cubes); //一个word判断完毕,对Vector重新实例化,以继续判断下一个word
return compareSC(centerCube,subWord.charAt(subWordLen-1)); //此时subWordLen=1
}
else{
for(int i=0;i<subWordLen;i++){
if(compareSC(destVs,wordChar[i])&&(i!=subWordLen-1)){
subWord=word.substring(i+1);
return compareVs(centerCube,subWord);
}
}
return false;
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Test ts=new Test();
//boolean b=ts.compareLetter("hello", 'h');
//boolean b=ts.compareSS("hello", "he");
//System.out.println("result: "+b);
ts.run();
}
}
private String[]words=new String[]{"admin","flex","aeiou"};
private Vector <String> centerCube=new Vector <String>();
private String[] srt;
//private int outInt;
public void Test(){}
public void setVector(String[]ss){
for(int i=0;i<ss.length;i++){
centerCube.addElement(ss[i]);
}
//System.out.println("VectorCube size: "+centerCube.size());
} //ok public String[] VecToStr(Vector ev){
int size=ev.size();
//System.out.println("Vector Size: "+size);
String[] st=new String[size];
for(int i=0;i<ev.size();i++){
st[i]=ev.elementAt(i).toString();
} //测试代码,Vector转化为String调用函数
return st;
} //ok
public void printString(String[]sa){
System.out.print("");
//String[]words=new String[]{"admin","flex"};
for(int i=0;i<sa.length;i++){
System.out.print(sa[i]+" ");
} //测试代码,Vector转化为String调用函数
System.out.println();
} //ok
public void run(){
this.setVector(cubes);
srt=this.VecToStr(centerCube);
System.out.println("String[] length: "+srt.length);
System.out.print("String[] cubes: ");
this.printString(srt); //测试代码,Vector转化为String
System.out.print("String[] word: ");
this.printString(words);
/* centerCube.removeElement("abcdef");
srt=this.VecToStr(centerCube);
System.out.println("String[] length: "+srt.length);
this.printString(srt);*/ //测试代码,Vector转化为String
boolean a=compareVs(centerCube,"adi"); //判断adiji是否“包含”于集合类centerCube中,返回布尔类型a
System.out.println("Test a:"+a); //测试代码,结果显示递归成功
composeWord(cubes,words);
}
public void composeWord(String[] cub,String[]word)
{
System.out.print("Results: {");
for(int i=0;i<word.length;i++){
//System.out.println("hello");
if(compareVs(centerCube,word[i])){
//outInt=i;
System.out.print(i+", ");
//System.out.print("true ");
}
else{
//System.out.println("Word");
//System.out.print(" false");
}
setVector(cubes);
}
System.out.println("}");
}
public boolean compareLetter(String destWord,char sourceChar){
for(int i=0;i<destWord.length();i++){
if(destWord.charAt(i)==sourceChar){
return true;
}
}
return false;
} //ok
public boolean compareSC(Vector destV,char sourceC){
String[] destWs=VecToStr(destV);
for(int i=0;i<destWs.length;i++){
if(compareLetter(destWs[i],sourceC)){
centerCube.removeElement(destWs[i]); //remove StringElement OK
return true;
}
}
return false;
}
public boolean compareVs(Vector destVs,String word){
//String[] destWs=VecToStr(destVs);
String subWord=word;
char[] wordChar=subWord.toCharArray();
int subWordLen=subWord.length();
if(subWordLen==1){
setVector(cubes); //一个word判断完毕,对Vector重新实例化,以继续判断下一个word
return compareSC(centerCube,subWord.charAt(subWordLen-1)); //此时subWordLen=1
}
else{
for(int i=0;i<subWordLen;i++){
if(compareSC(destVs,wordChar[i])&&(i!=subWordLen-1)){
subWord=word.substring(i+1);
return compareVs(centerCube,subWord);
}
}
return false;
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Test ts=new Test();
//boolean b=ts.compareLetter("hello", 'h');
//boolean b=ts.compareSS("hello", "he");
//System.out.println("result: "+b);
ts.run();
}
}
A 里面的字母在B里面是不是都有啊?如果是,你可以
1 把A里面每个字符串的字母放到Set a 里面
2 把B里面每个字符串的字母放到Set b 里面a.removeAll(b);
如果
a.size() > 0 则说明A里面有的字母在B里面是没有的!!!
比如上面的“admin”是可以组成的
但“ade”是不可以组成的,因为B中找不到3个字符串,分别含有‘a’,‘d’,‘e’