algorithm - Find all permutation of a string with certain position unchanged -
Given a string of words, say "omami", keep the uppercase letter constant (unchanged) but we change its position Small letter Output All possible permutations
For example. The given "omi" should produce this ["omi", "oyhmah"]
Here's what I did:
public static list & lt; String & gt; Indexing (strings) {list & lt; String & gt; Res = new arreelist & lt; String & gt; (); If (s == blank || s.length () == 0) {Return Res; } Stringbiller path = new string builder (s); & Lt; Character & gt; Candidates = new Arsuachi & lt; Character & gt; (); & Lt; Integer & gt; Status = New Arreelist & lt; Integer & gt; (); For (int i = 0; i & lt; s.length (); i ++) {char c = s.charAt (i); If (Character. ISLFBATIC (C) and character. Solar CAS (C)) (candidates.add (c); position.add (i);}} Boolean [] = = new boolean [candidates.size ()]; Assistant (Static, path, candidate, position, 0) return ridge;} public static zero assistant (list & lt; string & gt; res, stringbinder path, list & lt; character & gt; candidates, list & lt; integer & Position; int index) {if (index == position.size ()) {res.add (path.toString ()); return;} (int i = index; i & lt; position.size (); I ++) {for (int j = 0; j & lt; candidates.size () ; J ++) {path.setCharAt (position.get (i) candidates.get (j)); four c = candidates; far (j); assistant (reserve, path, candidate, status, index + 1); Candidates .add (j, c); The result for input "ABC" [APC, ACB, ACC, ACB] Basically, the outer loop is running in every possible situation, the internal loop tries every possible candidate, every possible situation I do not know why it has been duplicated "ACC, ACB"
this main point It seems like your inherent question is how to calculate all the permutations of a given set efficiently, which you can read about online (there are several ways). If you can calculate all the permutations of the lower case letter index, while respecting the posts of the upper case letters, the book is accessible by keeping each order of lower case letters with the original unchanged set of upper case letters. It is very easy to make you can output your strings. If you are having trouble with that part, then update your question and someone will be able to assist you.
Comments
Post a Comment