fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. vector<string> v;
  5.  
  6. void permutation(string &temp,int i){
  7. if(i == temp.length()){
  8. v.push_back(temp);
  9. }
  10.  
  11. for(int j=i;j<temp.length();j++){
  12. swap(temp[i],temp[j]);
  13. permutation(temp,i+1);
  14. swap(temp[i],temp[j]);
  15. }
  16. return;
  17. }
  18.  
  19. int main() {
  20. string s;
  21. cin >> s;
  22. string temp = s;
  23. int l = s.length();
  24.  
  25. permutation(temp,0);
  26. sort(v.begin(),v.end());
  27. for(auto &i : v){
  28. if(i == s)
  29. break;
  30.  
  31. cout << i << endl;
  32. }
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 4508KB
stdin
cab
stdout
abc
acb
bac
bca