编辑代码

import java.util.*;
import java.io.*;

class Main {

    public static int splitRule = 3;
    public static List checkList = new ArrayList(); 

	public static void main(String[] args) {
        String[] defaultArray = {"1","2","3","4","5","6","7","8","9"};

        List tempArray = new ArrayList();
        List tempIndex = new ArrayList(); 
        getList(defaultArray, tempIndex, true, tempArray);
        for(int i=0;i<tempArray.size();i++){
            System.out.println(tempArray.get(i));
        }
	}

    private static void getList(String[] defaultArray, List tempIndex, boolean isFirst, List tempArray){
        for(int i=0;i<defaultArray.length;i++){
            List tempIndexCopy = new ArrayList();
            if(!isFirst){
                tempIndexCopy = (List)deepCopy(tempIndex);
            }
            if(tempIndexCopy.contains(i)){
                
            }else{
                tempIndexCopy.add(i);
                if(tempIndexCopy.size() == defaultArray.length){
                    if(simpleCheck(tempIndex, defaultArray)) tempArray.add(getListStr(tempIndexCopy, defaultArray));
                }
                else{
                    if(tempIndexCopy.size() != (defaultArray.length - splitRule) || simpleCheck(tempIndex, defaultArray)){
                        getList(defaultArray, tempIndexCopy, false, tempArray);
                    }
                }
            }
        }
    }

    private static boolean simpleCheck(List tempIndex, String[] defaultArray){
        String str = "";
        List tempList = new ArrayList();
        for(int i=0;i<tempIndex.size();i++){
            tempList.add(defaultArray[Integer.parseInt(tempIndex.get(i).toString())]);
            if((i+1)%splitRule==0 && i!=0){
                str += getLastStr(tempList);
                tempList.clear();
            }
        }
        if(checkList.contains(str)){
            return false;
        }else{
            checkList.add(str);
            return true;
        }
    }

    private static String getLastStr(List tempList){
        int cheng = 1;
        int add = 0;
        for(int i=0;i<tempList.size();i++){
            cheng = cheng * Integer.parseInt(tempList.get(i).toString());
            add += Integer.parseInt(tempList.get(i).toString());
        }
        return "" + cheng + add;
    }

    private static String getListStr(List tempIndex, String[] defaultArray){
        String str = "";
        for(int i=0;i<tempIndex.size();i++){
            if(i%splitRule==0 && i!=0) str += ",";
            str += defaultArray[Integer.parseInt(tempIndex.get(i).toString())];
        }
        return str;
    }

    private static Object deepCopy(Object from) {
        Object obj = null;
        try {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream(bos);
            out.writeObject(from);
            out.flush();
            out.close();
 
            ObjectInputStream in = new ObjectInputStream(
                    new ByteArrayInputStream(bos.toByteArray()));
            obj = in.readObject();
        } catch(IOException e) {
            e.printStackTrace();
        } catch(ClassNotFoundException e2) {
            e2.printStackTrace();
        }
        return obj;
    }
}