解题思路:
注意事项:
参考代码:
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
public class Main {
static HashSet<Integer> set = new HashSet<Integer>();
static String str1="";
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
String str=scanner.next();
int n=str.length();
int[] a=new int[n];
for(int i=0;i<n;i++) {
a[i]=Integer.parseInt(""+str.charAt(i));
}
pd(a,0);
List<Integer> list = new ArrayList<>(set);
Collections.sort(list);
for(int i=0;i<list.size();i++) {
if(a.length==1)
System.out.printf("%d\n",list.get(i));
else if(a.length==2)
System.out.printf("%02d\n",list.get(i));
else if(a.length==3)
System.out.printf("%03d\n",list.get(i));
else if(a.length==4)
System.out.printf("%04d\n",list.get(i));
else if(a.length==5)
System.out.printf("%05d\n",list.get(i));
else
System.out.printf("%06d\n",list.get(i));
}
}
private static void pd(int[] a, int m) {
// TODO Auto-generated method stub
if(m==a.length) {
str1="";
for(int i=0;i<a.length;i++) {
str1=a[i]+str1;
}
set.add(Integer.parseInt(str1));
return;
}
for(int i=m;i<a.length;i++) {
int t=a[i];
a[i]=a[m];
a[m]=t;
pd(a,m+1);
t=a[i];
a[i]=a[m];
a[m]=t;
}
}
}
0.0分
0 人评分