Created
August 11, 2014 20:23
-
-
Save fntlnz/08be78ff9f01b2a47dec to your computer and use it in GitHub Desktop.
combinations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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