1. package com.visionsky; 
  2.  
  3. public class test { 
  4.  
  5.     private char[] numbers = new char[] { 'a''b''c','d','e'}; 
  6.     public int n; 
  7.     private String lastResult = ""
  8.  
  9.     private boolean validate(String s) { 
  10.         if (s.compareTo(lastResult) <= 0
  11.             return false
  12.         if (s.charAt(2) == 'b'
  13.             return false
  14.         if (s.indexOf("ce") >= 0 || s.indexOf("ec") >= 0
  15.             return false
  16.         return true
  17.     } 
  18.  
  19.     /* 
  20.      * index 用于判断当前result中存有字符串的序号 
  21.      * result 当前运行时字符串的结果 
  22.      */ 
  23.     public void list(String index, String result) { 
  24.         for (int i = 0; i < numbers.length; i++) { 
  25.             if (index.indexOf(i + 48) < 0) {//i+48 表示当前i的ascii码,即对i做char型类型转换,判断当前字符是否存在于result中 
  26.                 String s = result + String.valueOf(numbers[i]); 
  27.                 if (s.length() == numbers.length) { 
  28.                     if (validate(s)) { 
  29.                         System.out.println(s); 
  30.                         lastResult = s; 
  31.                         n++; 
  32.                     } 
  33.                      break
  34.                 } 
  35.                 list(index + String.valueOf(i), s); 
  36.             } 
  37.         } 
  38.     } 
  39.  
  40.     public static void main(String[] args) { 
  41.         test t = new test(); 
  42.         t.list(""""); 
  43.         System.out.println("总数:" + t.n); 
  44.  
  45.     }