Sample Input
3
aAb
abc
acba
Sample Output
Aab
Aba
aAb
abA
bAa
baA
abc
acb
bac
bca
cab
cba
aabc
aacb
abac
abca
acab
acba
baac
baca
bcaa
caab
caba
cbaa
对字符串进行全排列,字符的大小规则: 'A'<'a'<'B'<'b'<...<'Z'<'z'.
# include <iostream>
# include <cstring>
# include <algorithm>
using namespace std; bool cmp(const char &a, const char &b)
{
if (tolower(a) == tolower(b)) //把字符转换成小写字母,非字母字符不做出处理
{
return a < b;
}
else
return tolower(a) < tolower(b); } int main()
{
int num = ;
cin >> num;
while(num--)
{
char str[];
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 ;
}