fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. string operation1(string s){
  5. return s;
  6. }
  7.  
  8. string operation2(string s){
  9. string temp = s;
  10. sort(s.rbegin(), s.rend());
  11. string temp2 = s + temp;
  12. return temp2;
  13. }
  14.  
  15.  
  16. int main() {
  17. int t; cin >> t;
  18. while(t--){
  19. int n; cin >> n;
  20. string s; cin >> s; int len = s.length();
  21. string final;
  22. if(s[0]-'a' <= s[len-1]-'a')
  23. final = operation1(s);
  24. else
  25. final = operation2(s);
  26. cout << final << endl;
  27. }
  28. return 0;
  29. }
Success #stdin #stdout 0s 5288KB
stdin
5
4
cpm
2
grib
10
kupitimilablodarbuz
1000000000
capybara
6
abacaba
stdout
cpm
rigbgrib
kupitimilablodarbuz
yrpcbaaacapybara
abacaba