public static void main(String[] args) {
String str = "A/B/D; B/G; B/C/F";
StringBuffer sb = new StringBuffer();
if (str.contains("; ") && str.contains("/")) {
String[] semSplit = str.split("; ");
int semSplit_length = semSplit.length;
List<String[]> list = new ArrayList<String[]>();
for (int i = 0; i< semSplit_length; i ++) {
String[] Left_slash = semSplit[i].split("/");
list.add(Left_slash);
}
computeStr(list);
// System.out.println("LEFT SLASH :"+Left_slash.length+" Count:"+leftCount);
}
}
private static void computeStr(List<String[]> list) {
int[] num = new int[list.size()];
int[] postion = new int[list.size()];
postion[list.size() -1] =-1;
for(int i = 0; i < list.size(); i ++) {
num[i] = list.get(i).length;
}
while(getNextPostion(num, postion)) {
for(int i =0 ; i < postion.length; i ++) {
System.out.print(list.get(i)[postion[i]]);
}
System.out.println();
}
}
private static boolean getNextPostion(int[] num, int[] postion) {
postion[postion.length -1] ++;
for(int i = postion.length -1 ; i > 0; i --) {
if(postion[i] >= num[i]) {
postion[i -1] ++;
postion[i] = postion[i] % num[i];
}
}
if(postion[0] >= num[0]) {
return false;
} else {
return true;
}
}
这个是用来把字符串“String str = "A/B/D; B/G; B/C/F";”变成18个字符的算法
先以;做分隔,再以/做分隔
以;做分隔的字符都要取,以/做分隔的字符要取其中一个
也就是说,每一次取
A B D要取并取其中一个
B G 要取并取其中一个
B C F要取并取其中一个
那么所有的取法是什么
算法思想是:做加法,初法将值设为-1,每次做加1的动作,直到加满。进位就要根据所在位置的字符串的长度来进位。这样就能依次遍历所有。