//============================================================================
// Name : ForJob.cpp
// Author : yangyh
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
//从M个字符中选出N个字符的所有组合
#include <iostream>
using namespace std;

static int m = 0;
int print(const char * src, int begin, int len, char *dst, int index, int n) {

if (n == 0) {
dst[index]
= '\0';
printf(
"%d:%s\n", m++, dst);
return 1;
}
if (len < n)
return 0;
for (int i = begin; i < len; i++) {

dst[index]
= src[i];
print(src, i
+ 1, len, dst, index + 1, n - 1);

}
return 1;
}
int main(int argc, char* argv[]) {
printf(
"Hello World!\n");
char str[10] = "abcdefgh";
char dst[10];
print(str,
0, 8, dst, 0, 3);//从8个字符中找出3个字符的所有组合
printf("total:%d\n", m);
return 0;
}

相关文章:

  • 2022-12-23
  • 2021-07-02
  • 2021-11-26
  • 2021-05-17
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-19
  • 2021-06-17
  • 2022-01-04
  • 2022-12-23
  • 2022-12-23
  • 2019-06-26
  • 2021-09-30
相关资源
相似解决方案