打印一个字符串中字符的所有组合

来源:互联网 发布:广州亚信数据有限公司 编辑:程序博客网 时间:2024/05/21 09:38
#include #include char dest[50];void Reverse_str(char *src, int hight, int *count);int main(){char str[] = "abcde";int count = 0;printf("The previous string is :/n");puts(str);printf("----------------/n");Reverse_str(str, 0, &count);printf("/nThere %d assign ways!/n", count);return 0;}void Reverse_str(char *src, int hight, int *count){int len = strlen(src);int i = 0, j = 0;char *pstr = NULL;pstr = src;if(hight == len){for(i = 0; i < len; ++i){putchar(dest[i]);}printf("/t");(*count)++;if((*count) % 8 == 0){printf("/n");}return;}while(*pstr != '/0'){for(j = 0; j < hight; ++j){if(*pstr == dest[j]){break;}}if(j >= hight){dest[hight] = *pstr;Reverse_str(src, hight+1, count); }pstr++;}}
原创粉丝点击