Arrangement of strings

Source: Internet
Author: User

Title: Enter a string to print out all the permutations of the characters in the string. For example, the input string ABC prints out all the string ABC,ACB,BAC,BCA,CAB,CBA that can be arranged by the character A,b,c.

Analysis: First of all the characters that may appear in the first position, that is, the first character and all subsequent characters are exchanged. In the second step, a character is fixed, and all the characters in the back are arranged. The following characters can still be used in this way. is obviously a recursive process. The implementation is as follows:

Void permutation (CHAR* PSTR) {    if (pstr==null)          return;            permutation ( PSTR,PSTR);} Void permutation (Char* pstr,char* pbegin) {    if (*pBegin== ')      {        printf ("%s\n", pStr);     }     else    {        for (char*  pch=pbegin;*pch!= ' + '; ++pch)         {             char temp=*pCh;             *pCh=*pBegin;             *pBegin=temp;                          permutation (pstr,pbegin+1);                          temp=*pch;            *pch=*pbegin;             *pBegin=temp;         }    }}

The solution to the problem is: all combinations of characters, eight Queen questions, and so on.

This article from "Fairy Road thousands of dust Dream" blog, please be sure to keep this source http://secondscript.blog.51cto.com/9370042/1585597

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.