Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:100分,给出任意长度数字字符串,求所有不重复的组合 [Re:ruadergo]
Cappuccino





发贴: 49
积分: 4
于 2007-07-29 20:29 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
随便写了一个,勉强能用^_^

public class Pailie2
{
static List<String> usrInput = new LinkedList<String>();
static List<String> result = new LinkedList<String>();
public static void main(String[] args)
{
String str = "abcde";
init(str);
System.out.println(usrInput.size());
calc(str.length(),usrInput,"");
int count = 0;
for (String elem : result)
{
System.out.println(elem);
count++;
}
System.out.println("count:"+count);
}

//将用户输入的字符串装入到一个usrInput的list里面
public static void init(String str)
{
Set<Character> set = new HashSet<Character>();
for (int i = 0; i < str.length(); i++)
{
set.add(str.charAt(i));
}
for (Iterator it = set.iterator(); it.hasNext();)
{
Character elem = (Character)it.next();
usrInput.add(elem+"");
}
}

public static void calc(int maxlen,List<String> list,String prefix)
{
for (int i = 0; i < list.size(); i++)
{
String currentUnit = list.get(i);
if((prefix+currentUnit).length()==maxlen)
{
result.add(prefix+currentUnit);
}else
{
List<String> leftlist = new LinkedList<String>();
leftlist.addAll(list);
leftlist.remove(i);
calc(maxlen,leftlist,prefix+currentUnit);
}
}
}

}


Cappuccino edited on 2007-07-29 22:20


25了才开始学JAVA晚吗?

话题树型展开
人气 标题 作者 字数 发贴时间
6364 100分,给出任意长度数字字符串,求所有不重复的组合 ruadergo 227 2007-07-20 19:43
5242 Re:100分,给出任意长度数字字符串,求所有不重复的组合 Cappuccino 1337 2007-07-29 20:29

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923