思路:
对于递归的考察。类似于不断的二分枚举,总之考察的还是比较深入的,特别是用一个vector模拟栈的进出都是需要学习的地方。以后还需要仔细理解。
#include#include using namespace std;void SolveRecursively(char* s, int count, vector & result){ if (count == 0) { vector ::const_iterator iter; for (iter = result.begin(); iter != result.end(); ++iter) cout << *iter; cout << endl; } else { if (*s == '\0') return; result.push_back(*s); SolveRecursively(s + 1, count - 1, result); result.pop_back(); SolveRecursively(s + 1, count, result); }}void Combination(char* s){ if (s == nullptr) return; vector result; int len = strlen(s); for (int i = 1; i <= len; ++i) SolveRecursively(s, i, result);}