设计一个c语言四位数算法,问题用c或Java 写一个算法 :有5个数1,2,3,4,5 列出这5个数所有可能的组合?比如说一位数字有1,2,3,4,5五种可能,两位数字有,12,13,14,15,21...

import java.util.Arrays;

import java.util.Set;

import java.util.TreeSet;

public class GetAssemble {

public static Set set = new TreeSet();

public static void doSet(String start, String[] sourceList, int max) {

String[] olds = start.split("_");

if (olds.length == max) {

set.add(start.replaceAll("_", "").trim());

}

else {

for (int s = 0; s 

if (Arrays.asList(olds).contains(sourceList[s])) {

continue;

}

else {

doSet(start + "_" + sourceList[s], sourceList, max);

}

}

}

}

public static void doSet(String[] sourceList, int max) {

for (int start = 0; start 

doSet(sourceList[start], sourceList, max);

}

}

public static void print() {

System.out.println("Total:" + set.size());

int cols = 10;

for (String s : set) {

System.out.print(s + " ");

if (cols-- == 1) {

System.out.println();

cols = 10;

}

}

set.clear();

}

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

String[] haha = new String[] { "1", "2", "3", "4", "5" };

System.out.println();

System.out.println("  ");

doSet(haha, 5);

print();

}

}

解析看不懂?求助智能家教解答查看解答

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值