場景:
string[][]arr1=new string[3][];
arr1[0]=new string[]{"a","[^a]"};
arr1[1]=new string[]{"b","[^b]"};
arr1[2]=new string[]{"c","[^c]"};
把arr1[0],arr1[1],arr1[2] 進行組合,組合的規則:
(1){"a","[^a]"} x {"b","[^b]"} x{"c","[^c]"}
(2)組合的結果中必須同時有arr1[0],arr1[1],arr1[2]中的一個元素.
比如"abc"就是正确的,a[^b]b就是錯誤的,因為a[^b]b沒有{"c","[^c]"}中的元素.
"acb"是錯誤的,因為沒有按順序
/***
*
* @param a
* @param aa
* @param index : 初始值為0
*/
public static list<stringbuffer> cc(string[][] aa,int index,list<stringbuffer> list){
if(index>=aa.length){//說明已經周遊完成
return list;//并不是每次循環都會執行,最後才會執行此語句.
}
string cc[]=aa[index];
int length=cc.length;
list<stringbuffer> listnew=new arraylist<stringbuffer>();
if(list==null||list.size()==0){//首次循環
for(int i=0;i<length;i++){
listnew.add(new stringbuffer(cc[i]));
}
}else{
for(int j=0;j<list.size();j++){
stringbuffer sb=list.get(j);
stringbuffer sb2=new stringbuffer(sb);
sb2.append(cc[i]);
listnew.add(sb2);
}
list<stringbuffer> list33=cc(aa, ++index, listnew);
if(!valuewidget.isnullorempty(list33)){
return list33;
return null;
}
/***
* 組合
* @return
public static list<stringbuffer>assemble(string[][] aa){
return cc(aa, 0, null);
測試1:
@test
public void tset_cc(){
string[][]arr1=new string[3][];
list<stringbuffer> list=assemble(arr1);
system.out.println(list.size());
system.out.println(list);
測試結果:
8
[abc, [^a]bc, a[^b]c, [^a][^b]c, ab[^c], [^a]b[^c], a[^b][^c], [^a][^b][^c]]
測試2:
public void tset_cc2(){
arr1[0]=new string[]{"a"};
arr1[1]=new string[]{"b"};
arr1[2]=new string[]{"c"};
1
[abc]
測試3:
string[][]arr1=new string[2][];
arr1[0]=new string[]{"a","1","one"};
arr1[1]=new string[]{"b","2","two"};
// arr1[2]=new string[]{"c","3"};
9
[ab, 1b, oneb, a2, 12, one2, atwo, 1two, onetwo]