Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- string str;
- long long int i,j,t,n,ln,tln,div,x,y;
- long long int fac[30];
- fac[0]=1;
- for(j=1;j<=20;j++)
- fac[j]=fac[j-1]*j;
- cin>>t;
- while(t--){
- cin>>str;
- cin>>n;
- ln=str.size();
- for(i=0;i<ln;i++) {
- sort(str.begin() + i, str.end());
- if (n==0)
- break;
- x = i + n/fac[ln-i-1];
- swap(str[i], str[x]);
- n = n % fac[ln-i-1];
- }
- cout<<str<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement