package net.sahv.sssmiao.controller.wap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Stack;
import cn.hutool.core.convert.Convert;
public class SubListExport2 {
public static String[] ticket1 = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13",
"14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31",
"32", "33", "34", "35" };
public static String[] ticket2 = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", };
public static void main(String[] args) {
List<String> strings = Arrays.asList(ticket1);
List<String> strings2 = Arrays.asList(ticket2);
if (strings.size() == 2) {
} else {
List<List<String>> re1 = new ArrayList<>();
macSortStoredValue(re1, new Stack<>(), strings, 5, 0, 0);
// for (List<String> ss : re1) {
// System.out.println(ss);
// }
List<List<String>> re2 = new ArrayList<>();
macSortStoredValue(re2, new Stack<>(), strings2, 2, 0, 0);
// for (List<String> ss : re2) {
// System.out.println(ss);
// }
System.out.println(re1.size());
System.out.println(re2.size());
int i=0;
aa:for (List<String> ss : re1) {
for (List<String> ss2 : re2) {
System.out.println(Convert.toStr(ss).replace("[", "").replace("]", ""));
//System.out.println(ss+""+ss2);
i++;
// if(i>200) {
// break aa;
// }
// if(i>100 &&i<=200) {
// System.out.println(ss+""+ss2);
// }
}
}
System.out.println(i);
}
}
/**
*
* @param stringList 返回的集合
* @param stack 临时
* @param shu 子集长度
* @param targ 源
* @param has 当前长度
* @param cur 指针
*/
public static void macSortStoredValue(List<List<String>> stringList, Stack<String> stack, List<String> shu,
int targ, int has, int cur) {
// System.out.println(stack);
if (has == targ) {
if(iscontinuity(stack,3,ticket1)) {
// System.out.println(stack);
return;
}
List<String> s = new ArrayList<String>(stack);
stringList.add(s);
return;
}
for (int i = cur; i < shu.size(); i++) {
if (!stack.contains(shu.get(i))) {
stack.add(shu.get(i));
macSortStoredValue(stringList, stack, shu, targ, has + 1, i);
stack.pop();
}
}
}
/**
* 判断是否连续
*/
private static boolean iscontinuity(Stack<String> stack,Integer length,String[] tick) {
if(stack.size()<length) {
return false;
}else {
String first = stack.get(0);
int i = 0;
for( int y = 0;i<tick.length; y++) {
if(tick[y].equals(first)) {
i=y;
break;
}
}
for(int z=1;z<length;z++) {
i++;
if(!stack.get(z).equals(tick[i])) {
return false;
}
}
}
return true;
}
public static void macSortStoredValuetwo(List<List<String>> stringList, Stack<String> stack, List<String> shu,
int targ, int has, int cur) {
// System.out.println(stack);
if (has == targ) {
List<String> s = new ArrayList<String>(stack);
stringList.add(s);
return;
}
for (int i = cur; i < shu.size(); i++) {
if (!stack.contains(shu.get(i))) {
stack.add(shu.get(i));
macSortStoredValuetwo(stringList, stack, shu, targ, has + 1, i);
stack.pop();
}
}
}
}
11-24
05-05
5万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)