The title description enters a string that prints out all the permutations of the characters in the string in the dictionary order. For example, enter the string ABC and print out all the strings abc,acb,bac,bca,cab and CBA that can be arranged by the character A,b,c. The results are output in alphabetical order.
Input Description:
Enter a string that is not more than 9 in length (there may be a repetition of characters), and the characters include only uppercase and lowercase letters.
1 classSolution {2 Public:3 voidPermutation (stringStrintBeginintend,vector<string>&result)4 {5 if(Begin >end)6 {7 result.push_back (str);8 return;9 }Ten for(inti = begin; I <= end; ++i) One { A if(Str[begin]! = Str[i] | | begin = =i) - { - CharTEM =Str[begin]; theStr[begin] =Str[i]; -Str[i] =tem; -Permutation (str,begin+1, End,result); -TEM =Str[begin]; +Str[begin] =Str[i]; -Str[i] =tem; + } A } at } -vector<string> Permutation (stringstr) { -vector<string>Reslut; - if(str.length () = =0) - returnReslut; -Permutation (str,0, Str.length ()-1, Reslut); in Std::sort (Reslut.begin (), Reslut.end ()); - returnReslut; to } +};
Arrangement of strings