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

您没有登录

» Java开发网 » Java SE 综合讨论区 » 编程/算法/API  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:关于排列组合算法? [Re:cainiaosteven]
cainiaosteven





发贴: 3
积分: 0
于 2004-11-11 14:16 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 TestZH
{
public TestZH()
{
}
public java.util.ArrayList getZH(String a) throws Exception
{
java.util.ArrayList resultList = null;
java.util.ArrayList newList = new java.util.ArrayList();
for (int i = 0; i < a.length(); i++)
{
newList = getPP(a.charAt(i));
if (newList == null)
{
throw new Exception("取数出错!");
}

if (i == 0)
resultList = newList;
else
resultList = getLL(newList, resultList);

}

return resultList;
}

public java.util.ArrayList getPP(char c)
{
java.util.ArrayList resultList = new java.util.ArrayList();
if (c == 'a')
{
resultList.add("1");
resultList.add("2");
resultList.add("3");
}
if (c == 'b')
{
resultList.add("3");
resultList.add("6");
resultList.add("5");
}
if (c == 'c')
{
resultList.add("7");
resultList.add("6");
}
if (c == 'd')
{
resultList.add("8");
resultList.add("2");
}
if (c == 'e')
{
resultList.add("9");
}

return resultList;
}

public java.util.ArrayList getLL(java.util.ArrayList newList,
java.util.ArrayList oldList)
{
java.util.ArrayList resultList = new java.util.ArrayList();
String temp1, temp2;

for (int x = 0; x < oldList.size(); x++)
{
for (int y = 0; y < newList.size(); y++)
{
temp1 = (String) oldList.get(x);
temp2 = (String) newList.get(y);
resultList.add(temp1 + temp2);
}
}
return resultList;
}

public static void main(String args[])
{
TestZH tz = new TestZH();
java.util.ArrayList hzList = new java.util.ArrayList();

java.util.ArrayList pyList;

try
{
pyList = tz.getZH("abc");

for (int i = 0; i < pyList.size(); i++)
{
System.out.println( (i + 1) + ":" + (String) pyList.get(i));
}
}
catch (Exception ex)
{
System.out.println(ex.getMessage());
}

}

}




话题树型展开
人气 标题 作者 字数 发贴时间
23545 关于排列组合算法(算法高手请进) cainiaosteven 127 2004-11-11 14:06
18527 Re:关于排列组合算法? cainiaosteven 2109 2004-11-11 14:16

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-2020 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号
客服电话 0592-8750026    客服信箱 714923@qq.com    客服QQ 714923