| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 582 人关注过本帖
标题:排列组合
只看楼主 加入收藏
xiexiaoqiang
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2006-2-26
收藏
 问题点数:0 回复次数:4 
排列组合

楼主帮帮我,我头都想大了,还是写不出来。恕我是初学者,还请体谅///

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, “12” and “31” are different combinations from the input string “123”, but “21 is the same as “12”.

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

搜索更多相关主题的帖子: 排列 
2006-05-23 20:22
jiqijiqi
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2006-5-27
收藏
得分:0 
刚注册帐号,看到帖子,按照你的要求做了一个.
[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]

2006-05-27 23:50
★王者至尊★
Rank: 1
等 级:新手上路
帖 子:528
专家分:0
注 册:2006-3-28
收藏
得分:0 

晕啊 为什么我只能看到你贴的一部分


------Java 爱好者,论坛小混混,学习中------
2006-05-28 09:43
jiqijiqi
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2006-5-27
收藏
得分:0 
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;
}

}
}

2006-05-28 17:31
shiyide
Rank: 2
等 级:新手上路
威 望:4
帖 子:297
专家分:0
注 册:2006-2-22
收藏
得分:0 
能讲一下你的算法过程吗`?
最好加上注释谢谢`

学好编程,为中国的软件事业出一份力。
2006-05-28 21:40
快速回复:排列组合
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024501 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved