全排列(最快速next permutation)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char a[210];
int main()
{
    while(scanf("%s",a)!=EOF)
    {
        int len = strlen(a);
        sort(a, a+len);
        cout << a << endl;
        int k = 1;
        while(next_permutation(a, a+len))
        {
            cout << a << endl;
            k++;
//            cout << k << endl;
        }
        cout << k << endl;
    }
    string str;
    cin >> str;
    sort(str.begin(),str.end());
    cout << str << endl;
    while (next_permutation(str.begin(), str.end()))
        cout << str << endl;
    return 0;
}
View Code

 

posted @ 2015-03-20 21:02  PastLIFE  阅读(354)  评论(0编辑  收藏  举报