本文主要是介绍UVA 10098,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
/*注意全排列中有重复的如 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的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!