poj 1256 Anagram

http://poj.org/problem?id=1256

题意是说求出一个字符串的全排列,按字典序

需要注意的是字典序和传统意义上的字典序不同

重新定义了,A<a<B<b的顺序

需要自己重写cmp函数。

next_permutation好神....直接求出全排列.....

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <map>

using namespace std;
bool cmp(char a,char b)
{
    char x = tolower(a);
    char y = tolower(b);
    if (x==y)
    {
        return a<b;
    }
    else return x<y;
}
int n;
string st;

int main()
{
    cin>>n;
    while (n--)
    {

        cin>>st;
        sort(st.begin(),st.end(),cmp);
        do
        {
            cout<<st<<endl;
        }while (next_permutation(st.begin(),st.end(),cmp));
    }


    return 0;
}
原文地址:https://www.cnblogs.com/111qqz/p/4617577.html