UVa 10098 - Generating Fast

题目链接:UVa 10098 - Generating Fast

跟上道题用同样的方法。记得先排下序就行了。

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

const int MAX_N = 10 + 5;
int T;
char a[MAX_N];
int len;
int cmp(const void *a,const void *b)
{
    return *(char*)a - *(char*)b;
}
int main()
{
    cin>>T;
    while(T--)
    {
        cin>>a;
        len = strlen(a);
        qsort(a,len,sizeof(a[0]),cmp);
        do
        {
            cout<<a<<endl;
        }
        while(next_permutation(a,a+len));
        cout<<endl;
    }
    return 0;
}


你可能感兴趣的:(UVa 10098 - Generating Fast)