给定的一组字母生成所有可能的单词。单词按提示顺序排列。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
//So the right order of letters is 'A'<'a'<'B'<'b'<...<'Z'<'z'
map<char,int> hs;
char a[20];//抄博友程序
bool fun(char x,char y)
{
return hs[x]<hs[y];
}
int main()
{
hs['A']=0;
hs['a']=1;
hs['B']=2;
hs['b']=3;
hs['C']=4;
hs['c']=5;
hs['D']=6;
hs['d']=7;
hs['E']=8;
hs['e']=9;
hs['F']=10;
hs['f']=11;
hs['G']=12;
hs['g']=13;
hs['H']=14;
hs['h']=15;
hs['I']=16;
hs['i']=17;
hs['J']=18;
hs['j']=19;
hs['K']=20;
hs['k']=21;
hs['L']=22;
hs['l']=23;
hs['M']=24;
hs['m']=25;
hs['N']=26;
hs['n']=27;
hs['O']=28;
hs['o']=29;
hs['P']=30;
hs['p']=31;
hs['Q']=32;
hs['q']=33;
hs['R']=34;
hs['r']=35;
hs['S']=36;
hs['s']=37;
hs['T']=38;
hs['t']=39;
hs['U']=40;
hs['u']=41;
hs['V']=42;
hs['v']=43;
hs['W']=44;
hs['w']=45;
hs['X']=46;
hs['x']=47;
hs['Y']=48;
hs['y']=49;
hs['Z']=50;
hs['z']=51;
int n;
cin>>n;
for(int i=0;i<n;i++)
{
/*
string a;
cin>>a;
int m=a.size();
sort(a.begin(),a.end(),fun);
do{
for(int i=0;i<m;i++)
{
printf("%c",a[i]);
}
printf("\n");
}while(next_permutation(a.begin(),a.end(),fun));*/
scanf("%s",a);//抄博友程序
int m=strlen(a);
sort(a,a+m,fun);
do{
puts(a);//抄博友程序
/*
for(int i=0;i<m;i++)
{
printf("%c",a[i]);
}
printf("\n");*/
}while(next_permutation(a,a+m,fun));
}
return 0;
}