fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int sub(string str, string out[]){
  5. if(str.empty()){
  6. out[0] = "";
  7. return 1;
  8. }
  9. int smallOutput = sub(str.substr(1), out);
  10.  
  11. for(int i=0; i<smallOutput; i++)
  12. out[i + smallOutput] = str[0] + out[i];
  13.  
  14. return 2*smallOutput;
  15. }
  16.  
  17. int main() {
  18. // your code goes here
  19. string str;
  20. cin>>str;
  21. string* out = new string[100];
  22. int count = sub(str, out);
  23. sort(out[1].begin(), out[1].end());
  24. for(int i=0; i<count; i++)
  25. cout<<out[i]<<endl;
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0s 4392KB
stdin
abc
stdout
c
b
bc
a
ac
ab
abc