SHARE
TWEET

Untitled

a guest Jul 16th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<string>
  3. #include<vector>
  4. #include<set>
  5. #include<algorithm>
  6. using namespace std;
  7. typedef long long ll;
  8.  
  9. //set<string> univ;
  10.  
  11. bool swappable(string str, ll i, ll j)
  12. {
  13.     for (int k = i; k < j; k++)
  14.         if (str[k] == str[j])
  15.             return false;
  16.     return true;
  17. }
  18.  
  19.  
  20. void permute(string str, ll i)
  21. {
  22.     //base case;
  23.     if (i >= str.length())
  24.     {  
  25.         cout<<str<<endl;
  26.         return;
  27.     }
  28.  
  29.     for (ll j = i; j != str.length(); j++)
  30.     {
  31.         if (swappable(str, i, j))
  32.         {
  33.             swap(str[i], str[j]);
  34.             permute(str, i + 1);
  35.             swap(str[i], str[j]);
  36.         }
  37.     }
  38. }
  39.  
  40. int main()
  41. {
  42.     string str;
  43.     cin >> str;
  44.  
  45.     sort(str.begin(), str.end());
  46.     permute(str, 0);
  47.  
  48.     // for (string ste : univ)
  49.     // {
  50.     //  cout << ste << endl;
  51.     // }
  52.     return 0;
  53. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top