Advertisement
Saleh127

UVA 941

Aug 10th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. cout.tie(0);
  8.  
  9. long long fact[22];
  10. fact[0]=1;
  11. for(int i=1; i<=20; i++)
  12. {
  13. fact[i]=fact[i-1]*i;
  14. }
  15.  
  16. int t;
  17. cin>>t;
  18. while(t--)
  19. {
  20. string a;
  21. vector<char>app,ans;
  22. long long c,d,e,f,i,j,k,l,num;
  23.  
  24. cin>>a>>num;
  25. num++;
  26.  
  27. for(i=0; i<a.size(); i++)
  28. {
  29. app.push_back(a[i]);
  30. }
  31.  
  32. sort(app.begin(),app.end());
  33.  
  34. while(!app.empty())
  35. {
  36. c=fact[app.size()-1];
  37.  
  38. d=(num-1)/c;
  39.  
  40. ans.push_back(app[d]);
  41.  
  42. app.erase(app.begin()+d);
  43.  
  44. num-=(c*d);
  45. }
  46.  
  47. for(i=0; i<ans.size(); i++)
  48. {
  49. cout<<ans[i];
  50. }
  51. cout<<endl;
  52. }
  53.  
  54. return 0;
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement