http://zhedahht.blog.163.com/blog/static/2541117420114172812217/
思路:
对于递归的考察。类似于不断的二分枚举,总之考察的还是比较深入的,特别是用一个vector模拟栈的进出都是需要学习的地方。以后还需要仔细理解。
#include <iostream> #include <vector> using namespace std; void SolveRecursively(char* s, int count, vector<char>& result) { if (count == 0) { vector<char>::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<char> result; int len = strlen(s); for (int i = 1; i <= len; ++i) SolveRecursively(s, i, result); }