-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem12.cpp
80 lines (59 loc) · 1.25 KB
/
problem12.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
///link of problem : https://codeforces.com/contest/1935/problem/A
#include<bits/stdc++.h>
#include<iostream> ///* code by Ahmed Elnemr *///
using namespace std;
///template<typename type1,typename type2>
///#define b 10 --> const int b= 10;
#define ll long long
#define f first
#define sec second
#define endl "\n"
#define lp(n) for(ll i=0;i<n;i++)
#define set set<int>
#define vec vector<int>
#define vecll vector<ll>
void Fast()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
signed main() {
Fast();
int t=1; cin>>t;
while(t--) {
int n; cin>>n;
string s; cin>>s;
string rs = s;
reverse(rs.begin(),rs.end());
if(s==rs) {
cout<<s<<endl;
continue;
}
int l=0,r=s.size()-1;
bool flag=1;
while(l!=r) {
if(s[l]<s[r]) {
flag=1;
break;
}
if(s[l]==s[r]) {
l++; r--;
continue;
}
if(s[l]>s[r]) { ///abczdba
flag=0;
break;
}
l++; r--;
}
if(flag) {
cout<<s<<endl;
}
else {
rs+=s;
cout<<rs<<endl;
}
}
return 0;
}