第二次做全排列的题了,又有了不小的收获,c++中有专门做全排列的函数
next_permutation();所以方便了不少;在STL库中;
#include<iostream>
#include<algorithm>
#include<string>
#include<cctype>
using namespace std;
bool cmp(char a,char b){
if(tolower(a) == tolower(b)) //tolwer()函数作用是将大写字母转变为小写字母
return a < b;
else
return tolower(a) < tolower(b);
}
int main()
{ int n;
string str;
cin>>n;
while(n--)
{
cin >> str;
sort(str.begin(), str.end(),cmp);
cout << str << endl;
while (next_permutation(str.begin(), str.end(),cmp))
{
cout << str << endl;
}
// str.clear();
}
}