fork download
  1. #include <cstdio>
  2. #include <algorithm>
  3.  
  4. void powerSet(char *arr, int arrLen, int pos, int startPos, int length)
  5. {
  6. if (length == 0)
  7. printf("%.*s\n", pos, arr);
  8. else
  9. for (int i = startPos; i < arrLen; i++)
  10. {
  11. std::swap(arr[pos], arr[i]);
  12. powerSet(arr, arrLen, pos+1, i+1, length - 1);
  13. std::swap(arr[pos], arr[i]);
  14. }
  15. }
  16.  
  17. void powerSet(char *arr, int arrLen)
  18. {
  19. for (int i = 1; i <= arrLen; i++)
  20. powerSet(arr, 4, 0, 0, i);
  21. }
  22.  
  23. int main()
  24. {
  25. char arr[] = "1234";
  26. powerSet(arr, 4);
  27. return 0;
  28. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
1
2
3
4
12
13
14
23
24
34
123
124
134
234
1234