import java.util.HashSet;
import java.util.Set;
public class MySort {
public static void main(String[] args) {
//我的微博 http://weibo.com/namenode 欢迎大家关注
更多的Java笔试题
//我的邮箱 342187233@qq.com
也多多希望大家把见到的无论不会做的Java笔试题发过来一起分享、解决
Set list = getSort("122345");
for (StringBuffer sbf : list) {
System.out.println(sbf.toString());
}
}
public static Set getSort(String str) {
Set list = new HashSet();
list.add(new StringBuffer(str.subSequence(0, 1)));
for (int i = 1; i < str.length(); i++) {
Set temp = new HashSet();
String strtmp = str.substring(i, i + 1);
for (StringBuffer sbf : list) {
for (int j = 0; j <= sbf.length(); j++) {
StringBuffer sbftmp = new StringBuffer();
sbftmp.append(sbf.substring(0, j));
sbftmp.append(strtmp);
sbftmp.append(sbf.substring(j));
while (!(j >= sbftmp.length() - 1)
&& strtmp.charAt(0) == sbftmp.charAt(j + 1)) {
j++;
}
if (sbftmp.indexOf("35") >= 0 || sbftmp.indexOf("53") >=
0)
continue;
if (j == sbf.length() - 1
&& (sbftmp.length() >= 3 && sbftmp.charAt(2) -
'0' == 4))
continue;
temp.add(sbftmp);
}
}
list = temp;
}
return list;
}
}