按要求排序,然后调用next_permutation即可。
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
bool cmp(const char &a, const char &b)
{
if(a <= 'Z' && a >= 'A' && b <= 'Z' && b >= 'A')
return a < b;
if(a <= 'z' && a >= 'a' && b <= 'z' && b >= 'a')
return a < b;
if(a <= 'Z' && a >= 'A' && b <= 'z' && b >= 'a')
return a + 32 <= b;
if(a<='z' && a >='a' && b <= 'Z' && b >= 'A')
return a < (b + 32);
}
int main()
{
int num = 0;
cin >> num;
while(num--)
{
char str[100];
cin >> str;
int length = strlen(str);
sort(str, str+length, cmp);
cout << str << endl;
while(next_permutation(str, str + length, cmp))
{
cout << str << endl;
}
}
return 0;
}