62,633
社区成员
发帖
与我相关
我的任务
分享
public static void main(String args[]) {
for (int i1 = 3; i1 < 9; i1++) {
for (int i2 = 3; i2 < 9; i2++) {
for (int i3 = 3; i3 < 9; i3++) {
for (int i4 = 3; i4 < 9; i4++) {
for (int i5 = 3; i5 < 9; i5++) {
for (int i6 = 3; i6 < 9; i6++) {
for (int i7 = 3; i7 < 9; i7++) {
for (int i8 = 3; i8 < 9; i8++) {
System.out.println("" + i1 + i2 + i3
+ i4 + i5 + i6 + i7 + i8);
}
}
}
}
}
}
}
}
}
public class Test {
public static void main(String[] args) {
SelectTheNum(3,8,8);
}
private static void Select(int start, int min, int max, int length, int head){
if(start > head){
System.out.println(start);
return;
}
for(int m = min; m <= max; m++){
Select( start*10 + m, min, max, length, head);
}
}
public static void SelectTheNum(int min, int max, int length){
//参数min,max为要用到的数字的区间,length为要生成的数字的位数;
int head = 0;
while(length > 0){
head = head*10 + min;
length--;
}
Select(0,min,max,length,head);
}
}
public class Test {
public static void main(String[] args) {
SelectTheNum(3,8,8);
}
private static int getNumsbit(int i){
int temp = 0;
while(i > 0){
i /= 10;
temp++;
}
return temp;
}
private static void Select(int start, int min, int max, int length){
if(getNumsbit(start) == length){
System.out.println(start);
return;
}
for(int m = min; m <= max; m++){
Select( start*10 + m, min, max, length);
}
}
public static void SelectTheNum(int min, int max, int length){
//参数min,max为要用到的数字的区间,length为要生成的数字的位数;
Select(0,min,max,length);
}
}
//上面 int [][] 改用 short[][] 速度更快,short16位char16位,key可表示字符不受影响
public static void main(String[] args) throws MalformedURLException, IOException {
int[] key = {3, 4, 5, 6, 7, 8};
long time = System.currentTimeMillis();
int[][] tem = print(key, 8);
System.out.println("用时:"+(System.currentTimeMillis()-time)+"ms,一共:"+tem.length+"个");
/// 显示 start
int ttt = 1;
for (int i = 0; i < tem.length; i++) {
System.out.print(""+ttt+++":");//计数
for(int j=0;j<8;j++){
System.out.print(key[tem[i][j]]);
}
System.out.println();
}
/// 显示 end
}
/**
* 以key为关键字可重复的bit位数位的全排列
* @param key 显示的关键字
* @param bit 位数
*/
static int[][] print(int key[], int bit) {
int kl = key.length;
int Max = (int) Math.pow(kl, bit);
int[][] tem = new int[Max][bit];
for (int count = 0, j, b; count < Max; count++) {
for (j = bit - 1, b = count; j > -1; j--) {
tem[count][j] = b % kl;
b /= kl;
}
}
return tem;
}
/*run:
用时:2125ms,一共:1679616个
1:33333333
2:33333334
3:33333335
*/
public static void main(String[] args) throws MalformedURLException, IOException {
int[] key = {3,4,5,6,7,8};
int[][] bb = allOrder(key);
//显示结果
System.out.println("一共:"+bb.length+"个");
for (int[] s : bb) {
for (int i = 0; i < s.length; i++) {
System.out.print(s[i]);
if (i < s.length - 1) {
System.out.print(",");
}
}
System.out.println();
}
}
/**对key全排列
*/
static int[][] allOrder(final int[] key) {
java.util.LinkedList<int[]> list = new java.util.LinkedList<int[]>();
int length = key.length;
int[] itgr = new int[length];
System.arraycopy(key, 0, itgr, 0, length);
list.add(itgr);
for (int loop = 1; loop < length; loop++) {
int[][] tem = list.toArray(new int[list.size()][]);
for (int loop1 = 0; loop1 < loop; loop1++) {
for (int[] bft : tem) {
int[] itg = new int[length];
System.arraycopy(bft, 0, itg, 0, length);
int sw = itg[loop];
itg[loop] = itg[loop1];
itg[loop1] = sw;
list.add(itg);
}
}
}
return list.toArray(new int[list.size()][length]);
}
run:
一共:720个
3,4,5,6,7,8
4,3,5,6,7,8
5,4,3,6,7,8
5,3,4,6,7,8
3,5,4,6,7,8
4,5,3,6,7,8
6,4,5,3,7,8
6,3,5,4,7,8
6,4,3,5,7,8
--------
loop(0,1);
private static int cs=0;
public static void loop(int v, int l){
for(int i=8;i>=3;i--){
if((v+i*l)/10000000>0){
cs++;
// System.out.print(cs+":"+(v+i*l)+"\t\t");
// if(cs%10==0)System.out.println();
}else
loop(v+i*l,l*10);
}
}
int count=0;
for(int i=33333333; i<=88888888; i++) {
if(i/10000000>=3 && i/10000000<=8 &&
i%10000000/1000000>=3 && i%10000000/1000000<=8 &&
i%1000000/100000>=3 && i%1000000/100000<=8 &&
i%100000/10000>=3 && i%100000/10000<=8 &&
i%10000/1000>=3 && i%10000/1000<=8 &&
i%1000/100>=3 && i%1000/100<=8 &&
i%100/10>=3 && i%100/10<=8 ){
count++;
System.out.print(count + ":" + i + "\t\t");
if(count%10==0)System.out.println();
}
}