Full arrangement algorithm-STL implementation

Source: Internet
Author: User

Description of STL implementation for a fully arranged algorithm:

Given a string composed of different lower-case letters, all the strings are output in full order.
Assume that lowercase letters include 'A' <'B' <... <'y' <'Z', and the letters in the given string are arranged in ascending order.

Input:

The input contains only one row, which is a string consisting of different lower-case letters. It is known that the length of the string is between 1 and 6.

Output:

Output all the sorting methods of this string, one in each line. A relatively small alphabetic order is required to be arranged in front. The alphabetical order is defined as follows:
If S = s1s2... sk, T = t1t2... tk is known, S <T is equivalent to p (1 <= p <= k ),
S1 = t1, s2 = t2,..., sp-1 = tp-1, sp <tp is true.

Sample input:
abc
Sample output:
abcacbbacbcacabcba
Tip:

After the output of each sample is complete, a carriage return is output.

AC code:
#include
             
              #include
              
               #includeusing namespace std;int main(int argc,char *argv[]){char letters[10];while(scanf("%s",letters)!=EOF){printf("%s\n",letters);while(next_permutation(letters,letters+strlen(letters)))printf("%s\n",letters);printf("\n");}return 0;}
              
             
If cin is used, cout times out... STL is simple to solve this problem !!!

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.