Problem
将一个字符组全排序
Input
一个长度小于10的字符串,该字符串由数字1~9组成。字符不会重复出现。
Output
按数字在输入串中出现的次序从小到大的顺序输出该字符组的全排序
Sample Input
132
Sample Output
1 3 2
1 2 3
3 1 2
3 2 1
2 1 3
2 3 1
将一个字符组全排序
Input
一个长度小于10的字符串,该字符串由数字1~9组成。字符不会重复出现。
Output
按数字在输入串中出现的次序从小到大的顺序输出该字符组的全排序
Sample Input
132
Sample Output
1 3 2
1 2 3
3 1 2
3 2 1
2 1 3
2 3 1
- import java.util.ArrayList;
- import java.util.List;
- public class pailie {
- public static void main(String[] args) {
- pailie t = new pailie();
- t.contList();
- t.getAllArray(list, 0);
- }
- private static List<String> list = new ArrayList<String>();
- private void contList(){
- list.add("1");
- list.add("2");
- list.add("3");
- list.add("4");
- list.add("5");
- list.add("6");
- list.add("7");
- list.add("8");
- list.add("9");
- list.add("10");
- }
- public void getAllArray(List<String> inlist,int site){
- int tempsite = site;
- if (site >= inlist.size()) {
- return;
- }
- String firstNode = (String)inlist.get(site++);
- List<String> tempList = new ArrayList<String>(inlist);
- tempList.remove(tempsite);
- for (int i = 0; i < tempList.size(); i++ ) {
- System.out.print(firstNode);
- for (int j = i; j < tempList.size()+i; j++) {
- if (j < tempList.size()) {
- System.out.print(","+tempList.get(j));
- }else{
- System.out.print(","+tempList.get(j-tempList.size()));
- }
- }
- System.out.println("");
- }
- getAllArray(inlist,site);
- }
- }