fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int n, a[10], d = 1;
  7. string s;
  8. vector<string> res;
  9.  
  10. void saveString() {
  11. string r = "";
  12. for (int i = 0; i < n; i++)
  13. if (a[i] == 1)
  14. r += s[i];
  15. if (find(res.begin(), res.end(), r) == res.end())
  16. res.push_back(r);
  17. }
  18.  
  19. void binary(int i) {
  20. for (int j = 0; j <= 1; j++) {
  21. a[i] = j;
  22. if (i == n - 1)
  23. saveString();
  24. else
  25. binary(i + 1);
  26. }
  27. }
  28.  
  29. int main() {
  30. cin>> s;
  31. n = s.length();
  32. binary(0);
  33. for (int i = 0; i < res.size(); i++)
  34. cout << res[i] << endl;
  35. }
  36.  
Success #stdin #stdout 0s 5272KB
stdin
12345
stdout
5
4
45
3
35
34
345
2
25
24
245
23
235
234
2345
1
15
14
145
13
135
134
1345
12
125
124
1245
123
1235
1234
12345