打印一個字符串中字符的所有組合

#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++; } }
發佈了32 篇原創文章 · 獲贊 7 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章