-
Notifications
You must be signed in to change notification settings - Fork 0
/
C_permutations.cpp
41 lines (37 loc) · 1.13 KB
/
C_permutations.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(nullptr);
int n, q;
cin >> n >> q;
string s;
cin >> s;
while(q--)
{
string t;
cin >> t;
int x;
cin >> x;
if(t == "next_permutation")
{
while( x > 0 )
{
next_permutation(s.begin(),s.end());
x--;
}
cout << s << endl;
}
if(t == "prev_permutation")
{
while( x > 0 )
{
prev_permutation(s.begin(),s.end());
x--;
}
cout << s << endl;
}
}
}