fork download
  1. #include <bits/stdc++.h>
  2. #define faster() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  3. using namespace std;
  4. typedef long long ll;
  5. typedef unsigned long long ull;
  6. typedef unsigned int uint;
  7.  
  8. void solve()
  9. {
  10. int key,max,k,d=0,i=0;
  11. string s;
  12. cin >> k;
  13. cin >> s;
  14. while (d<k && i<s.size())
  15. {
  16. max=-1;
  17. for (int j=s.size()-1; j>i; j--)
  18. {
  19. if (s[j]-48>max)
  20. {
  21. max=s[j]-48;
  22. key=j;
  23. }
  24. }
  25. if (max>s[i]-48)
  26. {
  27. swap(s[i],s[key]);
  28. d++;
  29. }
  30. i++;
  31. }
  32. cout << s << endl;
  33. }
  34. int main()
  35. {
  36. faster();
  37. int t;
  38. cin >> t;
  39. while (t--)
  40. {
  41. solve();
  42. }
  43.  
  44. return 0;
  45. }
  46.  
  47.  
Success #stdin #stdout 0.04s 4416KB
stdin
Standard input is empty
stdout