1, 2, 2, 3, 4, 5 these six digits, write a main function in Java, print out all the different permutations, such as: 512234, 412345, etc. requirements: "4" can not be in third place, "3" and "5" can not be connected.
Package com.test;
Import java.util.ArrayList;
Import java.util.List;
/** * 1, 2, 2, 3, 4, 5 these six digits, write a main function in Java, print out all the different permutations, such as: 512234, 412345, etc. requirements: "4" can not be in third place, "3" and "5" can not be connected. * * @author SIMONE wangxinsh55@126.com 2009-6-12 * * public class Grouptest {public static list<string> List
= new Arraylist<string> (); /** * All sorting combinations of * constructed strings * @param str will be combined into the character * @param nstr source string set/public static void Group (S)
Tring str, string nstr) {if (Str.length ()!= nstr.length ()) {String rest = Getrest (str, NSTR);
for (int i = 0; i < rest.length (); i++) {String temp = str + rest.substring (i, i + 1); if (Temp.indexof ("4")!= 2 && temp.indexof ("1") = = && temp.indexof ("53") = = 1) {//filter display conditions, such as
The decision to remove this is to list all of the character set permutations and combinations System.out.println (temp);
if (!list.contains (temp)) {List.add (temp);
} Group (temp, NSTR); /** * Removes the character to be grouped from the source string * * @param str will be combined into the character * @param nstr source Word
String Set * @return remaining set of strings */public static string Getrest (String str, string nstr) {String rest = "";
if (Nstr.length () > Str.length ()) {rest = Nstr; for (int i = 0; i < str.length (); i++) {rest = Rest.replacefirst (str.substring (i, i + 1), "");/Note the
Replacefirst, instead of ReplaceAll} return rest;
public static void Main (string[] args) {Group ("", "122345");
System.out.println (List.tostring ()); }
}