atmystate用的是递归方式实现,我用非递归实现如下:
#include
#include
#define STR "abcd" //可以换成abcdef或其他字符,只要不超过8
int main()
{
int i = 0;
int j = 0;
int temp = 0;
char *p = STR;
int len = strlen(STR); //不包括末尾的'\0'
int totalCompose = 2 << (len-1);
printf("totalCompose=%d\n", totalCompose);
for (i = 0; i < totalCompose; ++i)
{
temp = i;
for (j = 0; j < len; ++j)
{
if (temp & 0x1)
printf("%c", p[j]);
temp >>= 1;
}
printf("\n");
}
return 0;
}