fork download
  1. #include <iostream>
  2. using namespace std;
  3. void helper(string s,string ans){
  4. if(s.length()==0){
  5. cout<<ans<<endl;
  6. return;
  7. }
  8.  
  9. for(int i = 0;i < s.size();i++){
  10. char c= s[i];
  11. string rest = s.substr(0,i)+s.substr(i+1);
  12.  
  13. helper(rest,ans+c);
  14. }
  15. }
  16. int main() {
  17. string s;cin>>s;
  18. helper(s,"");
  19. return 0;
  20. }
Success #stdin #stdout 0s 5308KB
stdin
abc
stdout
abc
acb
bac
bca
cab
cba