Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // print all combinations of string
- #include <iostream>
- #include <vector>
- using namespace std;
- void combinations(const char str[]);
- void combinations(const char str[], char buf[], bool used[], int bufpos, int cur, int len);
- void combinations(const char str[], vector<char>& buf, int start, int len);
- int main(int argc, char* argv[])
- {
- if(argc!=2)
- {
- cerr << argv[0] << " [string]" <<endl;
- return -1;
- }
- combinations(argv[1]);
- return 0;
- }
- void combinations(const char str[], vector<char>& buf, int start, int len)
- {
- for(int i=start; i<len; ++i)
- {
- buf.push_back(str[i]);
- //cout <<"bufsize: " << buf.size() << endl;
- for(size_t j=0; j<buf.size(); ++j)
- cout << buf[j];
- cout << endl;
- if( i < len)
- combinations(str, buf, i+1, len);
- buf.resize(buf.size()-1);
- }
- }
- void combinations(const char str[])
- {
- int len = strlen(str);
- vector<char> buf;
- combinations(str, buf, 0, len);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement