Advertisement
Guest User

Untitled

a guest
May 26th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include<vector>
  2. #include<string>
  3. #include<iostream>
  4. using namespace std;
  5.  
  6. void find(string& input, string cur, int pos, vector<string>&subset)
  7. {
  8. if (cur.length())
  9. subset.push_back(cur);
  10. if (pos == input.size())
  11. return;
  12. for(int i = pos; i < input.length(); i++)
  13. {
  14. cur.push_back(input[i]);
  15. find(input, cur, i+1, subset);
  16. cur.pop_back();
  17. }
  18. }
  19.  
  20. vector<string> find_all_subset(string input)
  21. {
  22. vector<string> subset;
  23. find(input, "", 0, subset);
  24. return subset;
  25. }
  26.  
  27. int main()
  28. {
  29. string input = "abcd";
  30. vector<string> result = find_all_subset(input);
  31. for (int i =0; i <result.size(); i++)
  32. cout<<result[i]<< ", "<<endl;
  33. return 1;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement