Advertisement
Shahd_Elmeniawy

prev & next permutation

Oct 4th, 2021 (edited)
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define TC ll testcase;   cin>>testcase;   while(testcase--)
  5. #define PI 3.14159265359
  6. #define ll long long
  7. #define U unsigned
  8. #define sz(m) (int)(m.size())
  9. #define endl "\n"
  10. #define el <<"\n"
  11. #define OO 2000000000
  12. #define M0D 1000000007
  13. #define all(SHA) SHA.begin(),SHA.end()
  14. #define cin(m) for(auto& it : m)cin>>it
  15. #define cout(m) for(auto& it : m)cout<<it<<" "
  16. #define B0Ma ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  17. //freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  18.  
  19. /* B0Ma
  20.                                  "Don't lose confidence in your abilities
  21.                                  * you have more than you can imagine
  22.                                  * and miracles don't need more than a second to come true "
  23. */
  24.  
  25. int main() {
  26.     B0Ma
  27.     ll x,o;       cin>>x>>o;
  28.     string s;       cin>>s;
  29.     while (o--){
  30.      string u;      cin>>u;
  31.      if(u=="prev_permutation"){
  32.          ll n;      cin>>n;
  33.          while (n--){
  34.              prev_permutation(all(s));
  35.          }
  36.          cout<<s el;
  37.      } else{
  38.          ll n;      cin>>n;
  39.          while (n--){
  40.              next_permutation(all(s));
  41.          }
  42.          cout<<s el;
  43.      }
  44.     }
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement