fork 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. reverse(s.begin(), s.end());
  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 final1 = operation1(s);
  22. string final2 = operation2(s);
  23. int x = 0;
  24. for(int i=0; i<s.length(); i++){
  25. if(final1[i] < final2[i]){
  26. x = 1;
  27. break;
  28. }
  29. else if(final1[i] > final2[i]){
  30. x=2;
  31. break;
  32. }
  33. }
  34. if(x == 0)cout << final1 << endl;
  35. else if(x == 1) cout << final1 << endl;
  36. else if(x==2) cout << final2 << endl;
  37. }
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 5288KB
stdin
6
4
cpm
2
grib
10
kupitimilablodarbuz
1000000000
capybara
6
abacaba
4
abaa
stdout
cpm
birggrib
kupitimilablodarbuz
arabypaccapybara
abacaba
aabaabaa