日期:2014-05-20 浏览次数:20751 次
public static void main(String[] args) { int[] a = {1,2,2,3,4,5}; TreeMap<String,String> tm = new TreeMap<String,String>(); f(a,0,"",tm); Iterator<String> it = tm.keySet().iterator(); while(it.hasNext()) { System.out.println(it.next()); } } public static void f(int[] a,int n,String str,TreeMap<String,String> tm) { if(n==a.length-1) { String str_2 = str+a[n]; if(!str_2.matches("\\d*?35\\d*?|\\d*?53\\d*?")&&!str_2.matches("[\\d]{2}4\\d+")) { tm.put(str_2, str_2); } } else { for(int i = n;i<a.length;i++) { int test = a[n]; a[n] = a[i]; a[i] = test; String str_2 = str+a[n]; f(a,n+1,str_2,tm); a[i] = a[n]; a[n] = test; } } }