fork download
  1.  
  2. #include <iostream>
  3. #include<bits/stdc++.h>
  4.  
  5. using namespace std;
  6.  
  7. void permute(string s,int l,int r)
  8. {
  9.  
  10. if(l==r)
  11. {
  12. cout<<s<<" ";
  13. return;
  14.  
  15. }
  16. else
  17. for(int i=l;i<r;i++)
  18. {
  19. swap(s[i],s[l]);
  20. permute(s,l+1,r);
  21. swap(s[i],s[l]);
  22. }
  23. }
  24.  
  25. int main()
  26. {
  27. permute("abc",0,3);
  28. return 0;
  29. }
Success #stdin #stdout 0s 5548KB
stdin
45
stdout
abc  acb  bac  bca  cba  cab