首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

如在字符串 abcd中选择 两个字母的所有组合,即C4 (2)=6中 分别为 ab ac ad bc bd cd解决办法

2012-03-23 
如在字符串 abcd中选择 两个字母的所有组合,即C4 (2)6中 分别为 ab ac ad bc bd cd如在字符串 abcd中选择

如在字符串 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
[解决办法]

C/C++ code
#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;} 

热点排行