发布网友 发布时间:2024-10-24 13:23
共2个回答
热心网友 时间:7分钟前
A,B,C,D,E不是数字吧
import java.util.ArrayList;
import java.util.List;
public class Permutation {
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
list.add("A");
list.add("B");
list.add("C");
list.add("D");
list.add("E");
permutation(list, new ArrayList<String>());
}
private static void permutation(List<String> src, List<String> desc) {
if(src.size() == 1){
desc.add(src.get(0));
StringBuffer sb = new StringBuffer();
for(String str: desc){
sb.append(str);
}
if(!(sb.charAt(2) == 'E' || sb.indexOf("CE") != -1 || sb.indexOf("EC") != -1)){
System.out.println(sb.toString());
}
}
final int size = desc.size();
for(int i = 0; i < src.size(); i++){
desc.add(src.get(i));
List<String> newSrcList = new ArrayList<String>();
newSrcList.addAll(src);
newSrcList.remove(i);
permutation(newSrcList, desc);
desc = desc.subList(0, size);
}
}
}
热心网友 时间:13分钟前
两个“B”是说有两个数字相同吗?