Search Here

Wednesday, June 3, 2015

UVa - 10098 ( Generating Fast Solution )

Tip : You need to learn STL ( <algrithm > ) to solve this problem . Otherwise it will be difficult to solve manually . See down .


Code :

#include<bits/stdc++.h>

using namespace std;

int main()
{
    char a[11];
    int n;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%s",a);
        int len = strlen(a);
        sort(a,a+len);
        do
        {
            printf("%s\n",a);
        }while(next_permutation(a,a+len)); //next_permutation(); is an STL.
        printf("\n");
    }
    return 0;
}

=> Need help . Leave a Comment .

2 comments:

  1. how this stl works pls explain

    ReplyDelete
    Replies
    1. http://www.cplusplus.com/reference/algorithm/next_permutation/

      Click on this link . You will have details about it . In general, Its an STL that Generate Next Permutations of the Current one .

      Delete