解题思路:
注意事项:
参考代码:
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
private static char[] a;
private static int lengt;
private static int[] v=new int[7];
private static char[] b=new char[7];
private static ArrayList<String> ck;
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
a=input.next().toCharArray();
ck=new ArrayList<>();
lengt=a.length;
for (int i = 0; i <lengt; i++) {
for (int j = i+1; j <lengt; j++) {
if(a[i]>a[j]){
char ch=a[i];
a[i]=a[j];
a[j]=ch;
}
}
}
dfs(0);
}
private static void dfs(int m) {
if(m>=lengt){
String st=new String(b);
if(!ck.contains(st)){
for (int i = 0; i <lengt; i++) {
System.out.print(b[i]);
}
System.out.println();
ck.add(st);
}
return;
}else{
for(int i=0;i<lengt;i++){
if(v[i]==0){
b[m]=a[i];
v[i]=1;
dfs(m+1);
v[i]=0;
}
}
}
}
}
0.0分
0 人评分