如在字符串 abcd中选择 两个字母的所有组合,即C4 (2)=6中 分别为 ab ac ad bc bd cd
如在字符串 abcd中选择 两个字母的所有组合,即C4 (2)=6中
分别为 ab ac ad bc bd cd
[解决办法]
http://blog.sina.com.cn/s/blog_6b88065a0100scfr.html
[解决办法]
#include <iostream>using std::cout;using std::endl;void combination(char *s,char *result,int n){ if(n == 0) { cout << result << " "; } else { int lens,point; for(lens = 0; s[lens];++lens); for(point = 0;result[point];++point); for(int i = 0; i < lens+1-n;++i) { result[point] = *s++; result[point + 1] ='\0'; combination(s,result,n - 1); } }}int main(){ const int n = 2; char s[]="abcd"; char result[n + 1]; memset(result,0,n + 1);combination(s,result,n);return 0;}