Advertisement
Guest User

Untitled

a guest
Dec 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. // next_permutation
  2. #include <bits/stdc++.h>
  3. #define IO ios::sync_with_stdio(0);cin.tie(0)
  4. #define endl '\n'
  5.  
  6. using namespace std;
  7.  
  8. int t;
  9. string s;
  10.  
  11. bool cmp(char, char);
  12.  
  13. int main()
  14. {
  15.     IO;
  16.     cin >> t;
  17.     cin.ignore();
  18.     while (t--) {
  19.         getline(cin, s);
  20.         sort(s.begin(), s.end(), cmp);
  21.         do {
  22.             cout << s << endl;
  23.         } while (next_permutation(s.begin(), s.end(), cmp));
  24.     }
  25.     return 0;
  26. }
  27.  
  28. bool cmp (char a, char b)
  29. {
  30.     char tmpa = tolower(a), tmpb = tolower(b);
  31.     return tmpa < tmpb || (tmpa == tmpb && a < b);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement