Arrangement of strings

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.