/*注意全排列中有重复的如 aac的全排列为
aac
aca
caa
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 100
int len, flag;
char str[MAX];
char num[MAX];
int used[MAX];
void dfs( int x )
{
int i;
if( x == len )
{
for( i = 0; i < len; i++ )
printf( "%c", num[i] );
printf( "\n" );
}
else
{
for( i = 0; i < len; i++ )
{
if( !used[i] && (flag||num[x] !=str[i]) )
{
flag = 1;
num[x] = str[i];
used[i] = 1;
dfs( x+1 );
flag = 0;
used[i] = 0;
}
}
}
}
int main()
{
int temp, i, j, N;
scanf( "%d\n", &N);
while( N-- )
{
gets(str);
len = strlen(str);
for( i = 0; i < len; i++ )
for( j = i; j < len; j++ )
if( str[i] > str[j] )
{
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
memset( num, 0, sizeof(num) );
memset( used, 0, sizeof(used) );
flag = 0;
dfs( 0 );
printf( "\n" );
}
return 0;
}
UVA 10098
最新推荐文章于 2017-07-03 04:00:43 发布