題意:
給出一個串,要求按照字典序輸出所有排列。
分析:
直接利用STL 裏的next_permutation()就好,重新定義一個cmp函數,沒有把cmp放進next_permutation(),我都WA哭了。。。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#define read freopen("q.in","r",stdin)
#define LL long long
#define maxn 35
using namespace std;
bool cmp(char x,char y)
{
if(tolower(x)!=tolower(y))return tolower(x)<tolower(y);
else return x<y;
}
int main()
{
//read;
//cout<<'a'-'A'<<endl;
int t;
cin>>t;
while(t--)
{
char str[maxn];
cin>>str;
int len=strlen(str);
sort(str,str+len,cmp);
do
{
printf("%s\n",str);
}while(next_permutation(str,str+len,cmp));
}
}