Skip to content

Instantly share code, notes, and snippets.

@fntlnz
Created August 11, 2014 20:23
Show Gist options
  • Save fntlnz/08be78ff9f01b2a47dec to your computer and use it in GitHub Desktop.
Save fntlnz/08be78ff9f01b2a47dec to your computer and use it in GitHub Desktop.
combinations
#include <iostream>
#include <vector>
void findCombinations(std::string c, std::string p, std::vector<std::string> &v) {
int i = 0;
int len = c.length();
if (p.length() < len) {
for (i = 0; i < len; i++) {
v.push_back(p + c[i]);
findCombinations(c, p + c[i], v);
}
}
}
int main(void) {
std::vector<std::string> combinations;
findCombinations("test", "", combinations);
for (std::vector<std::string>::iterator it = combinations.begin(); it != combinations.end(); ++it) {
std::cout << *it << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment