fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void permSum(string s, string perm)
  5. {
  6. cout << perm << endl;
  7. if(s.empty()) return;
  8. for(int i=0; i<s.length(); i++)
  9. permSum(s.substr(0,i)+s.substr(i+1, string::npos), perm+s[i]);
  10. }
  11.  
  12. int main() {
  13. permSum("abc", "");
  14. return 0;
  15. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
a
ab
abc
ac
acb
b
ba
bac
bc
bca
c
ca
cab
cb
cba