标签:今天 length tin bcd int acdb abd oid style
老早以前刚学程序的时候碰到了这么个问题,当时没想出来,今天突然想起来了这么个问题于是写了下,也算留个纪念吧
1 public static String itr; 2 3 public static void main(String[] args) { 4 String s = "abcd"; 5 printGroup(s); 6 } 7 8 public static void printGroup(String in){ 9 itr = in; 10 for (int i = 0; i < itr.length() ; i++) { 11 String c = itr.charAt(i)+""; 12 String low = itr.substring(0,i)+itr.substring(i+1); 13 print(c,low); 14 System.out.println(); 15 } 16 } 17 public static String cutStr(String cut){ 18 char[] sa = itr.toCharArray(); 19 char[] ca = cut.toCharArray(); 20 int k = sa.length-ca.length; 21 char[] str = new char[k]; 22 int i = 0; 23 A:for (char s : sa) { 24 for (char c : ca) { 25 if(s==c){ 26 continue A; 27 } 28 } 29 str[i++] = s; 30 if(i==k){ 31 break ; 32 } 33 } 34 return new String(str); 35 } 36 37 private static void print(String c,String str){ 38 for (int i = 0; i < str.length(); i++) { 39 String s = c + str.charAt(i); 40 System.out.print(s+" "); 41 print(s,cutStr(s)); 42 } 43 }
如果输入为abcd,结果则为
ab abc abcd abd abdc ac acb acbd acd acdb ad adb adbc adc adcb
ba bac bacd bad badc bc bca bcad bcd bcda bd bda bdac bdc bdca
ca cab cabd cad cadb cb cba cbad cbd cbda cd cda cdab cdb cdba
da dab dabc dac dacb db dba dbac dbc dbca dc dca dcab dcb dcba
标签:今天 length tin bcd int acdb abd oid style
原文地址:https://www.cnblogs.com/hetutu-5238/p/10877717.html