标签:
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; char str[100]; char resultstr[100]; int visit[100]; void dfs( int cur , int len) { if( cur == len ) { printf("%s \n", resultstr ); } int pre = -1; for( int i = 0 ; i < len ; i++ ) { if( !visit[i] ) { if( pre == -1 || str[pre] != str[i] ) { pre = i; resultstr[cur] = str[i] ; visit[i] = true; dfs( cur + 1 , len ); visit[i] = false; } else continue; } else continue; } } void sovle() { int len = strlen( str ); memset( resultstr , 0 , sizeof( resultstr ) ); memset( visit , 0 , sizeof( visit ) ); printf("==============================\n"); dfs( 0 , len ); printf("==============================\n\n"); } bool cmp ( const char &a , const char &b) { return a < b ; } int main() { memset( str , 0 ,sizeof( str ) ); while( ~scanf("%s",str ) ) { sort( str , str+strlen(str) ); sovle(); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zhping/p/4511700.html