同时也是 LETTers 2015 Summer II round 02-B - H
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
char str[15], m[100];
int num[15];
int main()
{
//freopen("H.in", "r", stdin);
int _, t1 = 'A', t2 = 'a';
for (int i = 0; i < 26 * 2; i++)
{
if (i & 1)
{
m[i] = t2++;
}
else
{
m[i] = t1++;
}
}
scanf("%d", &_);
while(_--)
{
scanf("%s", str);
int l = strlen(str);
for (int i = 0; i < l; i++)
{
if (str[i] >= 'A' && str[i] <= 'Z')
{
num[i] = (str[i] - 'A') * 2;
}
else
{
num[i] = (str[i] - 'a') * 2 + 1;
}
}
sort(num, num+l);
do{
for (int i = 0; i < l; i++)
{
printf("%c", m[num[i]]);
}
puts("");
}while(next_permutation(num, num+l));
}
return 0;
}