package com.mocha.util;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
public class cp {
static Set<String> set = new HashSet<>();
static Set<String> set1 = new HashSet<>();
public static void DFS(List<Integer> candidate, String prefix,int n){
if(prefix.length() ==n){
set.add(prefix);
// System.out.println(prefix);
}
for(int i=0; i<candidate.size(); i++){
List<Integer> temp = new LinkedList<Integer>(candidate);
int item = (int)temp.remove(i); // 取出被删除的元素,这个元素当作一个组合用掉了
DFS(temp, prefix+item,2);
}
}
public static void DFS1(List<Integer> candidate, String prefix,int n){
if(prefix.length() ==n){
set1.add(prefix);
// System.out.println(prefix);
}
for(int i=0; i<candidate.size(); i++){
List<Integer> temp = new LinkedList<Integer>(candidate);
int item = (int)temp.remove(i); // 取出被删除的元素,这个元素当作一个组合用掉了
DFS1(temp, prefix+item,2);
}
}
public static void main(String[] args) throws IOException {
//创建字符缓冲输出流对象
BufferedWriter bw = new BufferedWriter(new FileWriter("E:\\array1.txt"));
Set<String>strings =new HashSet<>();
Set<String>cph =new HashSet<>();
Integer[] array = {2,1,0,5,6};
String zm[] = {"G","Y","A","J"};
/*数 数 数 字母 数*/ /*数 数 字母 数 数*/
List<Integer> list = Arrays.asList(array);
DFS(list, "",2);
DFS1(list, "",2);
/*拼接英文*/
for (String s :set) {
for (String s1:zm) {
StringBuilder builder = new StringBuilder();
builder.append(s);
builder.append(s1);
strings.add(String.valueOf(builder));
}
}
/*组成最后的*/
for (String s :strings) {
for (String s1:set1) {
StringBuilder builder = new StringBuilder();
builder.append(s);
builder.append(s1);
cph.add(String.valueOf(builder));
}
}
/*输出*/
for (String s: cph) {
StringBuilder builder = new StringBuilder();
builder.append("xA·").append(s);
bw.write(String.valueOf(builder));
bw.newLine();
bw.flush();
}
//释放资源
bw.close();
}
}
可以根据自己的需要调整