楼主帮帮我,我头都想大了,还是写不出来。恕我是初学者,还请体谅///
Problem: Use your most hands-on programming language to implement a function that prints all possible combinations of the characters in a string. These combinations range in length from one to the length of the string. Two combinations that differ only in ordering of the characters ARE the same combination. In other words, “
For example, if we use “wxyz” as parameter for Combination(“wxyz”) the function will print out
w
x
y
z
wx
wy
wz
xy
xz
yz
wxy
wxz
wyz
xyz
wxyz
----------------解决方案--------------------------------------------------------
刚注册帐号,看到帖子,按照你的要求做了一个.
[CODE]public class pailie{
public static void main(String[] args){
String z=new String("wxyz");
int len=z.length();
String result="";
for(int b=1;b<=len;b++)
pailie(z,result,b);
}
public static void pailie(String z,String result,int b){
String res=result;
if(b==0){
System.out.println(result);
return;
}
int len=z.length();
for(int a=len-1;a>=0;a--){
res=res+z.charAt(a);
pailie(z.substring(0,a),res,b-1);
res=result;
}
}
}[/CODE]
----------------解决方案--------------------------------------------------------
晕啊 为什么我只能看到你贴的一部分
----------------解决方案--------------------------------------------------------
public class pailie{
public static void main(String[] args){
String z=new String("wxyz");
int len=z.length();
String result="";
for(int b=1;b<=len;b++)
pailie(z,result,b);
}
public static void pailie(String z,String result,int b){
String res=result;
if(b==0){
System.out.println(result);
return;
}
int len=z.length();
for(int a=len-1;a>=0;a--){
res=res+z.charAt(a);
pailie(z.substring(0,a),res,b-1);
res=result;
}
}
}
----------------解决方案--------------------------------------------------------
能讲一下你的算法过程吗`?
最好加上注释谢谢`
----------------解决方案--------------------------------------------------------