字符串中所有字母的组合

来自剑指offer,关于字符排列的延伸题目


输入一个字符串,例如“abcd”,输出所有字符的组合

 1 #include "stdafx.h"
 2 #include <iostream>
 3 using namespace std;
 4 /********************START COMBINATION**********************/
 5 //输入一个字符串,例如“abcd”,输出所有字符的组合
 6 char c[24];
 7 void dolistcombination(char *pbegin,char *s,int k)
 8 {
 9     if(k == 0){
10         *s ='';
11         printf("%s 
",c);
12     }
13     else{
14         for(char *ch = pbegin;*ch != ''; ch++,pbegin++){
15             *s = *ch;
16             dolistcombination(pbegin+1,s+1,k-1);
17         }
18     }
19 }
20 //字母组合的入口函数
21 void combination(char *str)
22 {
23     for(int i=0;i <sizeof(str)+1;i++)
24         dolistcombination(str,c,i);
25 }
原文地址:https://www.cnblogs.com/xiaoerhei/p/3679210.html