Advertisement
erfanul007

Permutation UVa 941

Dec 5th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. string str;
  7. vector<char>str2;
  8. int i,j,t,n,ln,tln,fac,div,x,y;
  9. cin>>t;
  10. while(t--){
  11. cin>>str;
  12. cin>>n;
  13. ln=str.size();
  14. tln=ln;
  15. y=0;
  16. while(y<ln){
  17. fac=1;
  18. for(j=1;j<=tln;j++)
  19. fac=fac*j;
  20. div=fac/ln;
  21. x=n/div;
  22. str2.push_back(str[x]);
  23. str.erase(str.begin()+(x+1));
  24. n=n-div*x;
  25. y++;
  26. tln--;
  27. }
  28. for(j=0;j<ln;j++)
  29. cout<<str2[j];
  30. cout<<endl;
  31. }
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement